Client-side search templates for online social networks

ABSTRACT

In one embodiment, a method includes receiving an unstructured text query from a first user of an online social network; and accessing, from a data store of the mobile client system, a set of nodes of a social graph of the online social network. The social graph includes a number of nodes and edges connecting the nodes. The nodes include a first node corresponding to the first user and a number of second nodes that each correspond to a concept or a second user associated with the online social network. The method also includes accessing, from the data store of the mobile client system, a set of grammar templates. Each grammar template includes one or more non-terminal tokens and one or more query tokens. The query tokens include references to zero or more second nodes and one or more edges and each grammar template is based on a natural-language string.

TECHNICAL FIELD

This disclosure generally relates to social graphs and performingsearches for objects within a social-networking environment.

BACKGROUND

A social-networking system, which may include a social-networkingwebsite, may enable its users (such as persons or organizations) tointeract with it and with each other through it. The social-networkingsystem may, with input from a user, create and store in thesocial-networking system a user profile associated with the user. Theuser profile may include demographic information, communication-channelinformation, and information on personal interests of the user. Thesocial-networking system may also, with input from a user, create andstore a record of relationships of the user with other users of thesocial-networking system, as well as provide services (e.g. wall posts,photo-sharing, event organization, messaging, games, or advertisements)to facilitate social interaction between or among users.

The social-networking system may transmit over one or more networkscontent or messages related to its services to a mobile or othercomputing device of a user. A user may also install softwareapplications on a mobile or other computing device of the user foraccessing a user profile of the user and other data within thesocial-networking system. The social-networking system may generate apersonalized set of content objects to display to a user, such as anewsfeed of aggregated stories of other users connected to the user.

Social-graph analysis views social relationships in terms of networktheory consisting of nodes and edges. Nodes represent the individualactors within the networks, and edges represent the relationshipsbetween the actors. The resulting graph-based structures are often verycomplex. There can be many types of nodes and many types of edges forconnecting nodes. In its simplest form, a social graph is a map of allof the relevant edges between all the nodes being studied.

SUMMARY OF PARTICULAR EMBODIMENTS

In particular embodiments, a method may parse a unstructured text queryusing grammar templates and entities stored client-side. Instead ofusing a full grammar model to generate suggested queries client-side,the suggested queries can be generated using a set of pre-definedtemplates and social-graph entities stored on the client. Apre-determined number of grammar templates and high-coefficient entitiescan be stored client-side so that suggested queries can be quicklygenerated client-side in response to text inputs from a user. Thesestored templates and entities may cover 90% or more of the queries runby users. The stored grammar templates may be determined based onglobally popular queries and/or personalize templates based on queriesthat are popular with the user, which may then be converted intotemplates. Popular queries/templates may include, for example, “Friendsof [user]”, “Photos of [user]”, or “Friends who live near [location]”.The stored entities may be determined by pre-selecting particularentity-types (e.g., all the user's friends, pages administered by theuser, groups the user belongs to, events the user has signed-up for, andapps the user has loaded), and/or by selecting a threshold number ofentities having the highest affinity.

In particular embodiments, when a user enters a text string into a queryfield, the client-side app will align that text string against thestored templates and compute the cost for each template. Essentially,cost is determined by penalizing each template for each deviation thetext string makes from the template (missing words, word variations,etc.). The lowest cost templates are then determined to be the bestmatches. The highest ranked templates may then displayed to the user assuggested queries. Similarly, the text string may be parsed to identifyentities that match portions of the text string. For example, if a usertypes in the text query “friends of f”, the client-side app may access astored grammar template for “friends of [user]” and match that up to thestored entity for the user “Fred”, thus suggesting the structured query“friends of Fred”. Alternatively, the client-side app may match the textquery to the grammar template “friends of friends of [user]”, andsuggest the partial structured query “friends of friends of . . . ”,which the user could select and then continue entering text.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates an example network environment associated with asocial-networking system.

FIG. 2 illustrates an example social graph.

FIG. 3 illustrates an example webpage of an online social network.

FIG. 4. illustrates an example mobile client system.

FIG. 5 illustrates an example user interface (UI) on an example mobileclient system.

FIG. 6 illustrates an graphical representation of an example costcalculation for matching a text input to a grammar template andsocial-graph entities.

FIG. 7 illustrates an graphical representation of an example costcalculation for matching a text input to a grammar template andsocial-graph entities.

FIG. 8 illustrates an graphical representation of an example costcalculation for matching a text input to a grammar template andsocial-graph entities.

FIG. 9 illustrates an example UI on an example mobile client system withan example structured search query.

FIG. 10 illustrates an example UI on an example mobile client systemwith an example structured search query.

FIG. 11 illustrates an example method for generating client-sidestructured search queries

FIG. 12 illustrates an example computer system.

DESCRIPTION OF EXAMPLE EMBODIMENTS

System Overview

FIG. 1 illustrates an example network environment 100 associated with asocial-networking system. Network environment 100 includes a clientsystem 130, a social-networking system 160, and a third-party system 170connected to each other by a network 110. Although FIG. 1 illustrates aparticular arrangement of client system 130, social-networking system160, third-party system 170, and network 110, this disclosurecontemplates any suitable arrangement of client system 130,social-networking system 160, third-party system 170, and network 110.As an example and not by way of limitation, two or more of client system130, social-networking system 160, and third-party system 170 may beconnected to each other directly, bypassing network 110. As anotherexample, two or more of client system 130, social-networking system 160,and third-party system 170 may be physically or logically co-locatedwith each other in whole or in part. Moreover, although FIG. 1illustrates a particular number of client systems 130, social-networkingsystems 160, third-party systems 170, and networks 110, this disclosurecontemplates any suitable number of client systems 130,social-networking systems 160, third-party systems 170, and networks110. As an example and not by way of limitation, network environment 100may include multiple client system 130, social-networking systems 160,third-party systems 170, and networks 110.

This disclosure contemplates any suitable network 110. As an example andnot by way of limitation, one or more portions of network 110 mayinclude an ad hoc network, an intranet, an extranet, a virtual privatenetwork (VPN), a local area network (LAN), a wireless LAN (WLAN), a widearea network (WAN), a wireless WAN (WWAN), a metropolitan area network(MAN), a portion of the Internet, a portion of the Public SwitchedTelephone Network (PSTN), a cellular telephone network, or a combinationof two or more of these. Network 110 may include one or more networks110.

Links 150 may connect client system 130, social-networking system 160,and third-party system 170 to communication network 110 or to eachother. This disclosure contemplates any suitable links 150. Inparticular embodiments, one or more links 150 include one or morewireline (such as for example Digital Subscriber Line (DSL) or Data OverCable Service Interface Specification (DOCSIS)), wireless (such as forexample Wi-Fi or Worldwide Interoperability for Microwave Access(WiMAX)), or optical (such as for example Synchronous Optical Network(SONET) or Synchronous Digital Hierarchy (SDH)) links. In particularembodiments, one or more links 150 each include an ad hoc network, anintranet, an extranet, a VPN, a LAN, a WLAN, a WAN, a WWAN, a MAN, aportion of the Internet, a portion of the PSTN, a cellulartechnology-based network, a satellite communications technology-basednetwork, another link 150, or a combination of two or more such links150. Links 150 need not necessarily be the same throughout networkenvironment 100. One or more first links 150 may differ in one or morerespects from one or more second links 150.

In particular embodiments, client system 130 may be an electronic deviceincluding hardware, software, or embedded logic components or acombination of two or more such components and capable of carrying outthe appropriate functionalities implemented or supported by clientsystem 130. As an example and not by way of limitation, a client system130 may include a computer system such as a desktop computer, notebookor laptop computer, netbook, a tablet computer, e-book reader, GPSdevice, camera, personal digital assistant (PDA), handheld electronicdevice, cellular telephone, smartphone, other suitable electronicdevice, or any suitable combination thereof. This disclosurecontemplates any suitable client systems 130. A client system 130 mayenable a network user at client system 130 to access network 110. Aclient system 130 may enable its user to communicate with other users atother client systems 130.

In particular embodiments, client system 130 may include a web browser132, such as MICROSOFT INTERNET EXPLORER, GOOGLE CHROME or MOZILLAFIREFOX, and may have one or more add-ons, plug-ins, or otherextensions, such as TOOLBAR or YAHOO TOOLBAR. A user at client system130 may enter a Uniform Resource Locator (URL) or other addressdirecting the web browser 132 to a particular server (such as server162, or a server associated with a third-party system 170), and the webbrowser 132 may generate a Hyper Text Transfer Protocol (HTTP) requestand communicate the HTTP request to server. The server may accept theHTTP request and communicate to client system 130 one or more Hyper TextMarkup Language (HTML) files responsive to the HTTP request. Clientsystem 130 may render a webpage based on the HTML files from the serverfor presentation to the user. This disclosure contemplates any suitablewebpage files. As an example and not by way of limitation, webpages mayrender from HTML files, Extensible Hyper Text Markup Language (XHTML)files, or Extensible Markup Language (XML) files, according toparticular needs. Such pages may also execute scripts such as, forexample and without limitation, those written in JAVASCRIPT, JAVA,MICROSOFT SILVERLIGHT, combinations of markup language and scripts suchas AJAX (Asynchronous JAVASCRIPT and XML), and the like. Herein,reference to a webpage encompasses one or more corresponding webpagefiles (which a browser may use to render the webpage) and vice versa,where appropriate.

In particular embodiments, social-networking system 160 may be anetwork-addressable computing system that can host an online socialnetwork. Social-networking system 160 may generate, store, receive, andtransmit social-networking data, such as, for example, user-profiledata, concept-profile data, social-graph information, or other suitabledata related to the online social network. Social-networking system 160may be accessed by the other components of network environment 100either directly or via network 110. In particular embodiments,social-networking system 160 may include one or more servers 162. Eachserver 162 may be a unitary server or a distributed server spanningmultiple computers or multiple datacenters. Servers 162 may be ofvarious types, such as, for example and without limitation, web server,news server, mail server, message server, advertising server, fileserver, application server, exchange server, database server, proxyserver, another server suitable for performing functions or processesdescribed herein, or any combination thereof. In particular embodiments,each server 162 may include hardware, software, or embedded logiccomponents or a combination of two or more such components for carryingout the appropriate functionalities implemented or supported by server162. In particular embodiments, social-networking system 164 may includeone or more data stores 164. Data stores 164 may be used to storevarious types of information. In particular embodiments, the informationstored in data stores 164 may be organized according to specific datastructures. In particular embodiments, each data store 164 may be arelational database. Particular embodiments may provide interfaces thatenable a client system 130, a social-networking system 160, or athird-party system 170 to manage, retrieve, modify, add, or delete, theinformation stored in data store 164.

In particular embodiments, social-networking system 160 may store one ormore social graphs in one or more data stores 164. In particularembodiments, a social graph may include multiple nodes—which may includemultiple user nodes (each corresponding to a particular user) ormultiple concept nodes (each corresponding to a particular concept)—andmultiple edges connecting the nodes. Social-networking system 160 mayprovide users of the online social network the ability to communicateand interact with other users. In particular embodiments, users may jointhe online social network via social-networking system 160 and then addconnections (i.e., relationships) to a number of other users ofsocial-networking system 160 whom they want to be connected to. Herein,the term “friend” may refer to any other user of social-networkingsystem 160 with whom a user has formed a connection, association, orrelationship via social-networking system 160.

In particular embodiments, social-networking system 160 may provideusers with the ability to take actions on various types of items orobjects, supported by social-networking system 160. As an example andnot by way of limitation, the items and objects may include groups orsocial networks to which users of social-networking system 160 maybelong, events or calendar entries in which a user might be interested,computer-based applications that a user may use, transactions that allowusers to buy or sell items via the service, interactions withadvertisements that a user may perform, or other suitable items orobjects. A user may interact with anything that is capable of beingrepresented in social-networking system 160 or by an external system ofthird-party system 170, which is separate from social-networking system160 and coupled to social-networking system 160 via a network 110.

In particular embodiments, social-networking system 160 may be capableof linking a variety of entities. As an example and not by way oflimitation, social-networking system 160 may enable users to interactwith each other as well as receive content from third-party systems 170or other entities, or to allow users to interact with these entitiesthrough an application programming interfaces (API) or othercommunication channels.

In particular embodiments, a third-party system 170 may include one ormore types of servers, one or more data stores, one or more interfaces,including but not limited to APIs, one or more web services, one or morecontent sources, one or more networks, or any other suitable components,e.g., that servers may communicate with. A third-party system 170 may beoperated by a different entity from an entity operatingsocial-networking system 160. In particular embodiments, however,social-networking system 160 and third-party systems 170 may operate inconjunction with each other to provide social-networking services tousers of social-networking system 160 or third-party systems 170. Inthis sense, social-networking system 160 may provide a platform, orbackbone, which other systems, such as third-party systems 170, may useto provide social-networking services and functionality to users acrossthe Internet.

In particular embodiments, a third-party system 170 may include athird-party content object provider. A third-party content objectprovider may include one or more sources of content objects, which maybe communicated to a client system 130. As an example and not by way oflimitation, content objects may include information regarding things oractivities of interest to the user, such as, for example, movie showtimes, movie reviews, restaurant reviews, restaurant menus, productinformation and reviews, or other suitable information. As anotherexample and not by way of limitation, content objects may includeincentive content objects, such as coupons, discount tickets, giftcertificates, or other suitable incentive objects.

In particular embodiments, social-networking system 160 also includesuser-generated content objects, which may enhance a user's interactionswith social-networking system 160. User-generated content may includeanything a user can add, upload, send, or “post” to social-networkingsystem 160. As an example and not by way of limitation, a usercommunicates posts to social-networking system 160 from a client system130. Posts may include data such as status updates or other textualdata, location information, photos, videos, links, music or othersimilar data or media. Content may also be added to social-networkingsystem 160 by a third-party through a “communication channel,” such as anewsfeed or stream.

In particular embodiments, social-networking system 160 may include avariety of servers, sub-systems, programs, modules, logs, and datastores. In particular embodiments, social-networking system 160 mayinclude one or more of the following: a web server, action logger,API-request server, relevance-and-ranking engine, content-objectclassifier, notification controller, action log,third-party-content-object-exposure log, inference module,authorization/privacy server, search module, ad-targeting module,user-interface module, user-profile store, connection store, third-partycontent store, or location store. Social-networking system 160 may alsoinclude suitable components such as network interfaces, securitymechanisms, load balancers, failover servers,management-and-network-operations consoles, other suitable components,or any suitable combination thereof. In particular embodiments,social-networking system 160 may include one or more user-profile storesfor storing user profiles. A user profile may include, for example,biographic information, demographic information, behavioral information,social information, or other types of descriptive information, such aswork experience, educational history, hobbies or preferences, interests,affinities, or location. Interest information may include interestsrelated to one or more categories. Categories may be general orspecific. As an example and not by way of limitation, if a user “likes”an article about a brand of shoes the category may be the brand, or thegeneral category of “shoes” or “clothing.” A connection store may beused for storing connection information about users. The connectioninformation may indicate users who have similar or common workexperience, group memberships, hobbies, educational history, or are inany way related or share common attributes. The connection informationmay also include user-defined connections between different users andcontent (both internal and external). A web server may be used forlinking social-networking system 160 to one or more client systems 130or one or more third-party system 170 via network 110. The web servermay include a mail server or other messaging functionality for receivingand routing messages between social-networking system 160 and one ormore client systems 130. An API-request server may allow a third-partysystem 170 to access information from social-networking system 160 bycalling one or more APIs. An action logger may be used to receivecommunications from a web server about a user's actions on or offsocial-networking system 160. In conjunction with the action log, athird-party-content-object log may be maintained of user exposures tothird-party-content objects. A notification controller may provideinformation regarding content objects to a client system 130.Information may be pushed to a client system 130 as notifications, orinformation may be pulled from client system 130 responsive to a requestreceived from client system 130. Authorization servers may be used toenforce one or more privacy settings of the users of social-networkingsystem 160. A privacy setting of a user determines how particularinformation associated with a user can be shared. The authorizationserver may allow users to opt in or opt out of having their actionslogged by social-networking system 160 or shared with other systems(e.g., third-party system 170), such as, for example, by settingappropriate privacy settings. Third-party-content-object stores may beused to store content objects received from third parties, such as athird-party system 170. Location stores may be used for storing locationinformation received from client systems 130 associated with users.Ad-pricing modules may combine social information, the current time,location information, or other suitable information to provide relevantadvertisements, in the form of notifications, to a user.

Social Graphs

FIG. 2 illustrates example social graph 200. In particular embodiments,social-networking system 160 may store one or more social graphs 200 inone or more data stores. In particular embodiments, social graph 200 mayinclude multiple nodes—which may include multiple user nodes 202 ormultiple concept nodes 204—and multiple edges 206 connecting the nodes.Example social graph 200 illustrated in FIG. 2 is shown, for didacticpurposes, in a two-dimensional visual map representation. In particularembodiments, a social-networking system 160, client system 130, orthird-party system 170 may access social graph 200 and relatedsocial-graph information for suitable applications. The nodes and edgesof social graph 200 may be stored as data objects, for example, in adata store (such as a social-graph database). Such a data store mayinclude one or more searchable or queryable indexes of nodes or edges ofsocial graph 200.

In particular embodiments, a user node 202 may correspond to a firstuser of social-networking system 160. As an example and not by way oflimitation, a user may be an individual (human user), an entity (e.g.,an enterprise, business, or third-party application), or a group (e.g.,of individuals or entities) that interacts or communicates with or oversocial-networking system 160. In particular embodiments, when a firstuser registers for an account with social-networking system 160,social-networking system 160 may create a first user node 202corresponding to the user, and store the user node 202 in one or moredata stores. Users and user nodes 202 described herein may, whereappropriate, refer to registered users and user nodes 202 associatedwith registered users. In addition or as an alternative, users and usernodes 202 described herein may, where appropriate, refer to users thathave not registered with social-networking system 160. In particularembodiments, a user node 202 may be associated with information providedby a user or information gathered by various systems, includingsocial-networking system 160. As an example and not by way oflimitation, a user may provide his or her name, profile picture, contactinformation, birth date, sex, marital status, family status, employment,education background, preferences, interests, or other demographicinformation. In particular embodiments, a user node 202 may beassociated with one or more data objects corresponding to informationassociated with a user. In particular embodiments, a user node 202 maycorrespond to one or more webpages.

In particular embodiments, a concept node 204 may correspond to aconcept. As an example and not by way of limitation, a concept maycorrespond to a place (such as, for example, a movie theater,restaurant, landmark, or city); a website (such as, for example, awebsite associated with social-network system 160 or a third-partywebsite associated with a web-application server); an entity (such as,for example, a person, business, group, sports team, or celebrity); aresource (such as, for example, an audio file, video file, digitalphoto, text file, structured document, or application) which may belocated within social-networking system 160 or on an external server,such as a web-application server; real or intellectual property (suchas, for example, a sculpture, painting, movie, game, song, idea,photograph, or written work); a game; an activity; an idea or theory;another suitable concept; or two or more such concepts. A concept node204 may be associated with information of a concept provided by a useror information gathered by various systems, including social-networkingsystem 160. As an example and not by way of limitation, information of aconcept may include a name or a title; one or more images (e.g., animage of the cover page of a book); a location (e.g., an address or ageographical location); a website (which may be associated with a URL);contact information (e.g., a phone number or an email address); othersuitable concept information; or any suitable combination of suchinformation. In particular embodiments, a concept node 204 may beassociated with one or more data objects corresponding to informationassociated with concept node 204. In particular embodiments, a conceptnode 204 may correspond to one or more webpages.

In particular embodiments, a node in social graph 200 may represent orbe represented by a webpage (which may be referred to as a “profilepage”). Profile pages may be hosted by or accessible tosocial-networking system 160. Profile pages may also be hosted onthird-party websites associated with a third-party server 170. As anexample and not by way of limitation, a profile page corresponding to aparticular external webpage may be the particular external webpage andthe profile page may correspond to a particular concept node 204.Profile pages may be viewable by all or a selected subset of otherusers. As an example and not by way of limitation, a user node 202 mayhave a corresponding user-profile page in which the corresponding usermay add content, make declarations, or otherwise express himself orherself. As another example and not by way of limitation, a concept node204 may have a corresponding concept-profile page in which one or moreusers may add content, make declarations, or express themselves,particularly in relation to the concept corresponding to concept node204.

In particular embodiments, a concept node 204 may represent athird-party webpage or resource hosted by a third-party system 170. Thethird-party webpage or resource may include, among other elements,content, a selectable or other icon, or other inter-actable object(which may be implemented, for example, in JavaScript, AJAX, or PHPcodes) representing an action or activity. As an example and not by wayof limitation, a third-party webpage may include a selectable icon suchas “like,” “check in,” “eat,” “recommend,” or another suitable action oractivity. A user viewing the third-party webpage may perform an actionby selecting one of the icons (e.g., “eat”), causing a client system 130to transmit to social-networking system 160 a message indicating theuser's action. In response to the message, social-networking system 160may create an edge (e.g., an “eat” edge) between a user node 202corresponding to the user and a concept node 204 corresponding to thethird-party webpage or resource and store edge 206 in one or more datastores.

In particular embodiments, a pair of nodes in social graph 200 may beconnected to each other by one or more edges 206. An edge 206 connectinga pair of nodes may represent a relationship between the pair of nodes.In particular embodiments, an edge 206 may include or represent one ormore data objects or attributes corresponding to the relationshipbetween a pair of nodes. As an example and not by way of limitation, afirst user may indicate that a second user is a “friend” of the firstuser. In response to this indication, social-networking system 160 maytransmit a “friend request” to the second user. If the second userconfirms the “friend request,” social-networking system 160 may createan edge 206 connecting the first user's user node 202 to the seconduser's user node 202 in social graph 200 and store edge 206 associal-graph information in one or more of data stores 24. In theexample of FIG. 2, social graph 200 includes an edge 206 indicating afriend relation between user nodes 202 of user “A” and user “B” and anedge indicating a friend relation between user nodes 202 of user “C” anduser “B.” Although this disclosure describes or illustrates particularedges 206 with particular attributes connecting particular user nodes202, this disclosure contemplates any suitable edges 206 with anysuitable attributes connecting user nodes 202. As an example and not byway of limitation, an edge 206 may represent a friendship, familyrelationship, business or employment relationship, fan relationship,follower relationship, visitor relationship, subscriber relationship,superior/subordinate relationship, reciprocal relationship,non-reciprocal relationship, another suitable type of relationship, ortwo or more such relationships. Moreover, although this disclosuregenerally describes nodes as being connected, this disclosure alsodescribes users or concepts as being connected. Herein, references tousers or concepts being connected may, where appropriate, refer to thenodes corresponding to those users or concepts being connected in socialgraph 200 by one or more edges 206.

In particular embodiments, an edge 206 between a user node 202 and aconcept node 204 may represent a particular action or activity performedby a user associated with user node 202 toward a concept associated witha concept node 204. As an example and not by way of limitation, asillustrated in FIG. 2, a user may “like,” “attended,” “played,”“listened,” “cooked,” “worked at,” or “watched” a concept, each of whichmay correspond to a edge type or subtype. A concept-profile pagecorresponding to a concept node 204 may include, for example, aselectable “check in” icon (such as, for example, a clickable “check in”icon) or a selectable “add to favorites” icon. Similarly, after a userclicks these icons, social-networking system 160 may create a “favorite”edge or a “check in” edge in response to a user's action correspondingto a respective action. As another example and not by way of limitation,a user (user “C”) may listen to a particular song (“Imagine”) using aparticular application (SPOTIFY, which is an online music application).In this case, social-networking system 160 may create a “listened” edge206 and a “used” edge (as illustrated in FIG. 2) between user nodes 202corresponding to the user and concept nodes 204 corresponding to thesong and application to indicate that the user listened to the song andused the application. Moreover, social-networking system 160 may createa “played” edge 206 (as illustrated in FIG. 2) between concept nodes 204corresponding to the song and the application to indicate that theparticular song was played by the particular application. In this case,“played” edge 206 corresponds to an action performed by an externalapplication (SPOTIFY) on an external audio file (the song “Imagine”).Although this disclosure describes particular edges 206 with particularattributes connecting user nodes 202 and concept nodes 204, thisdisclosure contemplates any suitable edges 206 with any suitableattributes connecting user nodes 202 and concept nodes 204. Moreover,although this disclosure describes edges between a user node 202 and aconcept node 204 representing a single relationship, this disclosurecontemplates edges between a user node 202 and a concept node 204representing one or more relationships. As an example and not by way oflimitation, an edge 206 may represent both that a user likes and hasused at a particular concept. Alternatively, another edge 206 mayrepresent each type of relationship (or multiples of a singlerelationship) between a user node 202 and a concept node 204 (asillustrated in FIG. 2 between user node 202 for user “E” and conceptnode 204 for “SPOTIFY”).

In particular embodiments, social-networking system 160 may create anedge 206 between a user node 202 and a concept node 204 in social graph200. As an example and not by way of limitation, a user viewing aconcept-profile page (such as, for example, by using a web browser or aspecial-purpose application hosted by the user's client system 130) mayindicate that he or she likes the concept represented by the conceptnode 204 by clicking or selecting a “Like” icon, which may cause theuser's client system 130 to transmit to social-networking system 160 amessage indicating the user's liking of the concept associated with theconcept-profile page. In response to the message, social-networkingsystem 160 may create an edge 206 between user node 202 associated withthe user and concept node 204, as illustrated by “like” edge 206 betweenthe user and concept node 204. In particular embodiments,social-networking system 160 may store an edge 206 in one or more datastores. In particular embodiments, an edge 206 may be automaticallyformed by social-networking system 160 in response to a particular useraction. As an example and not by way of limitation, if a first useruploads a picture, watches a movie, or listens to a song, an edge 206may be formed between user node 202 corresponding to the first user andconcept nodes 204 corresponding to those concepts. Although thisdisclosure describes forming particular edges 206 in particular manners,this disclosure contemplates forming any suitable edges 206 in anysuitable manner.

Typeahead Processes

In particular embodiments, one or more client-side and/or backend(server-side) processes may implement and utilize a “typeahead” featurethat may automatically attempt to match social-graph elements (e.g.,user nodes 202, concept nodes 204, or edges 206) to informationcurrently being entered by a user in an input form rendered inconjunction with a requested webpage (such as, for example, auser-profile page, a concept-profile page, a search-results webpage, oranother suitable page of the online social network), which may be hostedby or accessible in the social-networking system 160. In particularembodiments, as a user is entering text to make a declaration, thetypeahead feature may attempt to match the string of textual charactersbeing entered in the declaration to strings of characters (e.g., names,descriptions) corresponding to user, concepts, or edges and theircorresponding elements in the social graph 200. In particularembodiments, when a match is found, the typeahead feature mayautomatically populate the form with a reference to the social-graphelement (such as, for example, the node name/type, node ID, edgename/type, edge ID, or another suitable reference or identifier) of theexisting social-graph element.

In particular embodiments, as a user types or otherwise enters text intoa form used to add content or make declarations in various sections ofthe user's profile page, home page, or other page, the typeahead processmay work in conjunction with one or more frontend (client-side) and/orbackend (server-side) typeahead processes (hereinafter referred tosimply as “typeahead process”) executing at (or within) thesocial-networking system 160 (e.g., within servers 162), tointeractively and virtually instantaneously (as appearing to the user)attempt to auto-populate the form with a term or terms corresponding tonames of existing social-graph elements, or terms associated withexisting social-graph elements, determined to be the most relevant orbest match to the characters of text entered by the user as the userenters the characters of text. Utilizing the social-graph information ina social-graph database or information extracted and indexed from thesocial-graph database, including information associated with nodes andedges, the typeahead processes, in conjunction with the information fromthe social-graph database, as well as potentially in conjunction withvarious others processes, applications, or databases located within orexecuting within social-networking system 160, may be able to predict auser's intended declaration with a high degree of precision. However,the social-networking system 160 can also provide users with the freedomto enter essentially any declaration they wish, enabling users toexpress themselves freely.

In particular embodiments, as a user enters text characters into a formbox or other field, the typeahead processes may attempt to identifyexisting social-graph elements (e.g., user nodes 202, concept nodes 204,or edges 206) that match the string of characters entered in the user'sdeclaration as the user is entering the characters. In particularembodiments, as the user enters characters into a form box, thetypeahead process may read the string of entered textual characters. Aseach keystroke is made, the frontend-typeahead process may transmit theentered character string as a request (or call) to the backend-typeaheadprocess executing within social-networking system 160. In particularembodiments, the typeahead processes may communicate via AJAX(Asynchronous JavaScript and XML) or other suitable techniques, andparticularly, asynchronous techniques. In particular embodiments, therequest may be, or comprise, an XMLHTTPRequest (XHR) enabling quick anddynamic sending and fetching of results. In particular embodiments, thetypeahead process may also transmit before, after, or with the request asection identifier (section ID) that identifies the particular sectionof the particular page in which the user is making the declaration. Inparticular embodiments, a user ID parameter may also be sent, but thismay be unnecessary in some embodiments, as the user may already be“known” based on the user having logged into (or otherwise beenauthenticated by) the social-networking system 160.

In particular embodiments, the typeahead process may use one or morematching algorithms to attempt to identify matching social-graphelements. In particular embodiments, when a match or matches are found,the typeahead process may transmit a response (which may utilize AJAX orother suitable techniques) to the user's client system 130 that mayinclude, for example, the names (name strings) or descriptions of thematching social-graph elements as well as, potentially, other metadataassociated with the matching social-graph elements. As an example andnot by way of limitation, if a user entering the characters “pok” into aquery field, the typeahead process may display a drop-down menu thatdisplays names of matching existing profile pages and respective usernodes 202 or concept nodes 204, such as a profile page named or devotedto “poker” or “pokemon”, which the user can then click on or otherwiseselect thereby confirming the desire to declare the matched user orconcept name corresponding to the selected node. As another example andnot by way of limitation, upon clicking “poker,” the typeahead processmay auto-populate, or causes the web browser 132 to auto-populate, thequery field with the declaration “poker”. In particular embodiments, thetypeahead process may simply auto-populate the field with the name orother identifier of the top-ranked match rather than display a drop-downmenu. The user may then confirm the auto-populated declaration simply bykeying “enter” on his or her keyboard or by clicking on theauto-populated declaration.

More information on typeahead processes may be found in U.S. patentapplication Ser. No. 12/763,162, filed 19 Apr. 2010, and U.S. patentapplication Ser. No. 13/556,072, filed 23 Jul. 2012, which areincorporated by reference.

Structured Search Queries

FIG. 3 illustrates an example webpage of an online social network. Inparticular embodiments, a first user (also referred to as the “user” or“querying user,” corresponding to a particular user node 202) may submita query to the social-network system 160 by inputting text into asearch-query field 350. A first user of an online social network maysearch for information relating to a specific subject matter (e.g.,users, concepts, external content or resource) by providing a shortphrase describing the subject matter, often referred to as a “searchquery,” to a search engine. The query may be an unstructured text queryand may comprise one or more text strings (which may include one or moren-grams). In general, a first user may input any character string intosearch-query field 350 to search for content on the social-networkingsystem 160 that matches the text query. The social-networking system 160may then search a data store 164 (or, in particular, a social-graphdatabase) to identify content matching the query. The search engine mayconduct a search based on the query phrase using various searchalgorithms and generate search results that identify resources orcontent (e.g., user-profile pages, content-profile pages, or externalresources) that are most likely to be related to the search query. Toconduct a search, a first user may input or transmit a search query tothe search engine. In response, the search engine may identify one ormore resources that are likely to be related to the search query, eachof which may individually be referred to as a “search result,” orcollectively be referred to as the “search results” corresponding to thesearch query. The identified content may include, for example,social-graph elements (i.e., user nodes 202, concept nodes 204, edges206), profile pages, external webpages, or any combination thereof. Thesocial-networking system 160 may then generate a search-results webpagewith search results corresponding to the identified content and transmitthe search-results webpage to the first user. The search results may bepresented to the user, often in the form of a list of links on thesearch-results webpage, each link being associated with a differentwebpage that contains some of the identified resources or content. Inparticular embodiments, each link in the search results may be in theform of a Uniform Resource Locator (URL) that specifies where thecorresponding webpage is located and the mechanism for retrieving it.The social-networking system 160 may then transmit the search-resultswebpage to the web browser 132 on the first user's client system 130.The first user may then click on the URL links or otherwise select thecontent from the search-results webpage to access the content from thesocial-networking system 160 or from an external system (such as, forexample, a third-party system 170), as appropriate. The resources may beranked and presented to the user according to their relative degrees ofrelevance to the search query. The search results may also be ranked andpresented to the user according to their relative degree of relevance tothe first user. In other words, the search results may be personalizedfor the querying user based on, for example, social-graph information,user information, search or browsing history of the user, or othersuitable information related to the user. In particular embodiments,ranking of the resources may be determined by a ranking algorithmimplemented by the search engine. As an example and not by way oflimitation, resources that are more relevant to the search query or tothe user may be ranked higher than the resources that are less relevantto the search query or the user. In particular embodiments, the searchengine may limit its search to resources and content on the onlinesocial network. However, in particular embodiments, the search enginemay also search for resources or contents on other sources, such as athird-party system 170, the internet or World Wide Web, or othersuitable sources. Although this disclosure describes querying thesocial-networking system 160 in a particular manner, this disclosurecontemplates querying the social-networking system 160 in any suitablemanner.

In particular embodiments, the typeahead processes described herein maybe applied to search queries entered by a user. As an example and not byway of limitation, as a user enters text characters into a search field,a typeahead process may attempt to identify one or more user nodes 202,concept nodes 204, or edges 206 that match the string of charactersentered search field as the user is entering the characters. As thetypeahead process receives requests or calls including a string orn-gram from the text query, the typeahead process may perform or causesto be performed a search to identify existing social-graph elements(i.e., user nodes 202, concept nodes 204, edges 206) having respectivenames, types, categories, or other identifiers matching the enteredtext. The typeahead process may use one or more matching algorithms toattempt to identify matching nodes or edges. When a match or matches arefound, the typeahead process may transmit a response to the user'sclient system 130 that may include, for example, the names (namestrings) of the matching nodes as well as, potentially, other metadataassociated with the matching nodes. The typeahead process may thendisplay a drop-down menu 300 that displays names of matching existingprofile pages and respective user nodes 202 or concept nodes 204, anddisplays names of matching edges 206 that may connect to the matchinguser nodes 202 or concept nodes 204, which the user can then click on orotherwise select thereby confirming the desire to search for the matcheduser or concept name corresponding to the selected node, or to searchfor users or concepts connected to the matched users or concepts by thematching edges. Alternatively, the typeahead process may simplyauto-populate the form with the name or other identifier of thetop-ranked match rather than display a drop-down menu 300. The user maythen confirm the auto-populated declaration simply by keying “enter” ona keyboard or by clicking on the auto-populated declaration. Upon userconfirmation of the matching nodes and edges, the typeahead process maytransmit a request that informs the social-networking system 160 of theuser's confirmation of a query containing the matching social-graphelements. In response to the request transmitted, the social-networkingsystem 160 may automatically (or alternately based on an instruction inthe request) call or otherwise search a social-graph database for thematching social-graph elements, or for social-graph elements connectedto the matching social-graph elements as appropriate. Although thisdisclosure describes applying the typeahead processes to search queriesin a particular manner, this disclosure contemplates applying thetypeahead processes to search queries in any suitable manner.

In connection with search queries and search results, particularembodiments may utilize one or more systems, components, elements,functions, methods, operations, or steps disclosed in U.S. patentapplication Ser. No. 11/503,093, filed 11 Aug. 2006, U.S. patentapplication Ser. No. 12/977,027, filed 22 Dec. 2010, and U.S. patentapplication Ser. No. 12/978,265, filed 23 Dec. 2010, which areincorporated by reference.

In particular embodiments, in response to a structured query receivedfrom a querying user, the social-networking system 160 may generate oneor more search results, where each search result matches (orsubstantially matches) the terms of the structured query. Thesocial-networking system 160 may receive a structured query from aquerying user. In response to the structured query, thesocial-networking system 160 may generate one or more search resultscorresponding to the structured query. Each search result may includelink to a profile page and a description or summary of the profile page(or the node corresponding to that page). The search results may bepresented and transmitted to the querying user as a search-results page.The structured query used to generate a particular search-results pageis shown in query field 350, and the various search results generated inresponse to the structured query are illustrated in a field forpresented search results. In particular embodiments, the query field 350may also serve as the title bar for the page. In other words, the titlebar and query field 350 may effectively be a unified field on thesearch-results page. The search-results page may also include a fieldfor modifying search results and a field for providing suggestedsearches. When generating the search results, the social-networkingsystem 160 may generate one or more snippets for each search result,where the snippets are contextual information about the target of thesearch result (i.e., contextual information about the social-graphentity, profile page, or other content corresponding to the particularsearch result). Although this disclosure describes and illustratesparticular search-results pages, this disclosure contemplates anysuitable search-results pages.

More information on generating search results may be found in U.S.patent application Ser. No. 13/731,939, filed 31 Dec. 2012, which isincorporated by reference.

Client-Side Search Templates

FIG. 4 illustrates an example mobile client system 130. This disclosurecontemplates mobile client system 130 taking any suitable physical form.In particular embodiments, mobile client system 130 may be a computingsystem as described below. As example and not by way of limitation,mobile client system 130 may be a single-board computer system (SBC)(such as, for example, a computer-on-module (COM) or system-on-module(SOM)), a laptop or notebook computer system, a mobile telephone, asmartphone, a personal digital assistant (PDA), a tablet computersystem, or a combination of two or more of these. In particularembodiments, mobile client system 130 may have a touch sensor 132 as aninput component. In the example of FIG. 4, touch sensor 132 isincorporated on a front surface of mobile client system 130. In the caseof capacitive touch sensors, there may be two types of electrodes:transmitting and receiving. These electrodes may be connected to acontroller designed to drive the transmitting electrodes with electricalpulses and measure the changes in capacitance from the receivingelectrodes caused by a touch or proximity input. In the example of FIG.4, one or more antennae 134A-B may be incorporated into one or moresides of mobile client system 130. Antennae 134A-B are components thatconvert electric current into radio waves, and vice versa. Duringtransmission of signals, a transmitter applies an oscillating radiofrequency (RF) electric current to terminals of antenna 134A-B, andantenna 134A-B radiates the energy of the applied the current aselectromagnetic (EM) waves. During reception of signals, antennae 134A-Bconvert the power of an incoming EM wave into a voltage at the terminalsof antennae 134A-B. The voltage may be transmitted to a receiver foramplification.

In particular embodiments, mobile client system 130 many include acommunication component coupled to antennae 134A-B for communicatingwith an Ethernet or other wire-based network or a wireless NIC (WNIC),wireless adapter for communicating with a wireless network, such as forexample a WI-FI network or modem for communicating with a cellularnetwork, such third generation mobile telecommunications (3G), or LongTerm Evolution (LTE) network. This disclosure contemplates any suitablenetwork and any suitable communication component 20 for it. As anexample and not by way of limitation, mobile client system 130 maycommunicate with an ad hoc network, a personal area network (PAN), alocal area network (LAN), a wide area network (WAN), a metropolitan areanetwork (MAN), or one or more portions of the Internet or a combinationof two or more of these. One or more portions of one or more of thesenetworks may be wired or wireless. As another example, mobile clientsystem 130 may communicate with a wireless PAN (WPAN) (such as, forexample, a BLUETOOTH WPAN), a WI-FI network, a WI-MAX network, acellular telephone network (such as, for example, a Global System forMobile Communications (GSM), 3G, or LTE network), or other suitablewireless network or a combination of two or more of these. Mobile clientsystem 130 may include any suitable communication component for any ofthese networks, where appropriate.

FIG. 5 illustrates an example UI of an example mobile client system. Inparticular embodiments, a user may submit a query to the social-networksystem 160 by inputting text into a search-query field 350 of the UI ofmobile client system 130. As described above, a user of an online socialnetwork may search for information by providing a short phrasedescribing the subject matter, often referred to as a “search query,” toa search engine. Furthermore, a user may input any character string intosearch-query field 350 to search for social-graph entities on thesocial-networking system 160 that matches the text query. Thesocial-networking system 160 may then search a data store 164 (or, inparticular, a social-graph database) to identify social-graph entitiesthat match the query. As described below, mobile client system 130 mayidentify one or more structured queries based on the text input intosearch-query field 350 by the user. In particular embodiments, theidentified structured queries may be displayed in drop-down menu 300. Inparticular embodiments, in a case where the text query is not matched toa pre-determined number of structured queries using grammar templatesstored on mobile client system 130, the text query may be sent tosocial-networking system 160, where full context-free grammar models maybe used to generate a suggested query based on a natural-language stringgenerated by the grammar model.

In particular embodiments, in response to a text query received from afirst user (i.e., the querying user), the mobile client system 130 maygenerate one or more structured queries rendered in a natural-languagesyntax, where each structured query includes query tokens thatcorrespond to one or more identified social-graph elements. Structuredqueries may allow a querying user to search for content that isconnected to particular users or concepts in the social graph 200 byparticular edge types. As an example and not by way of limitation, themobile client system 130 may receive an unstructured text query from afirst user. In response, the mobile client system 130 (via, for example,a server-side element detection process) may access the social graph 200and then parse the text query to identify social-graph elements thatcorresponded to n-grams from the text query. The mobile client system130 may then access a grammar model, such as a context-free grammarmodel, which includes a plurality of grammar templates, described below.The identified social-graph elements may be used as terminal tokens(“query tokens”) in the grammar templates. The selected grammartemplates may then be used to generate one or more structured queriesthat include the query tokens referencing the identified social-graphelements. These structured queries may be based on strings generated bythe grammar templates, such that they are rendered with references tothe appropriate social-graph elements using a natural-language syntax.The structured queries may be displayed in a drop-down menu 300 (via,for example, a client-side typeahead process), where the first user canthen select an appropriate query to search for the desired content. Someof the advantages of using the structured queries described hereininclude finding users of the online social network based upon limitedinformation, bringing together virtual indexes of content from theonline social network based on the relation of that content to varioussocial-graph elements, or finding content related to you and/or yourfriends. By using this process, the output of the natural-languagerendering process may be efficiently parsed, for example, to generatemodified or alternative structured queries. Furthermore, since the rulesused by this process are derived from the grammar model, anymodification to the rules of the grammar model can be immediatelyreflected in the rendering process. Although this disclosure describesand illustrates generating particular structured queries in a particularmanner, this disclosure contemplates generating any suitable structuredqueries in any suitable manner.

In particular embodiments, the mobile client system 130 may receive froma querying/first user (corresponding to a first user node 202) anunstructured text query. As an example and not by way of limitation, afirst user may want to search for other users who: (1) are first-degreefriends of the first user; and (2) are associated with StanfordUniversity (i.e., the user nodes 202 are connected by an edge 206 to theconcept node 204 corresponding to the school “Stanford”). The first usermay then enter a text query “friends stanford” into search-query field350. As used herein, reference to an unstructured text query may referto a simple text string inputted by a user. The text query may, ofcourse, be structured with respect to standard language/grammar rules(e.g. English language grammar). However, the text query will ordinarilybe unstructured with respect to social-graph elements. In other words, asimple text query will not ordinarily include embedded references toparticular social-graph elements. Thus, as used herein, a structuredquery refers to a query that contains references to particularsocial-graph elements, allowing the search engine to search based on theidentified elements. Furthermore, the text query may be unstructuredwith respect to formal query syntax. In other words, a simple text querywill not necessarily be in the format of a query command that isdirectly executable by a search engine. Although this disclosuredescribes receiving particular queries in a particular manner, thisdisclosure contemplates receiving any suitable queries in any suitablemanner.

In particular embodiments, mobile client system 130 may parse theunstructured text query (also simply referred to as a search query)received from the first user (i.e., the querying user) to identify oneor more n-grams. In general, an n-gram is a contiguous sequence of nitems from a given sequence of text or speech. The items may becharacters, phonemes, syllables, letters, words, base pairs, prefixes,or other identifiable items from the sequence of text or speech. Then-gram may comprise one or more characters of text (letters, numbers,punctuation, etc.) entered by the querying user. An n-gram of size onecan be referred to as a “unigram,” of size two can be referred to as a“bigram” or “digram,” of size three can be referred to as a “trigram,”and so on. Each n-gram may include one or more parts from the text queryreceived from the querying user. In particular embodiments, each n-grammay comprise a character string (e.g., one or more characters of text)entered by the first user. As an example and not by way of limitation,the mobile client system 130 may parse the text query “friends stanford”to identify the following n-grams: friends; stanford; friends stanford.As another example and not by way of limitation, the mobile clientsystem 130 may parse the text query “friends in palo alto” to identifythe following n-grams: friends; in; palo; alto; friends in; in palo;palo alto; friend in palo; in palo also; friends in palo alto. Inparticular embodiments, each n-gram may comprise a contiguous sequenceof n items from the text query. Although this disclosure describesparsing particular queries in a particular manner, this disclosurecontemplates parsing any suitable queries in any suitable manner.

In particular embodiments, mobile client system 130 may determine orcalculate, for each n-gram identified in the text query, a score todetermine whether the n-gram corresponds to a social-graph element. Thescore may be, for example, a confidence score, a probability, a quality,a ranking, another suitable type of score, or any combination thereof.As an example and not by way of limitation, the mobile client system 130may determine a probability score (also referred to simply as a“probability”) that the n-gram corresponds to a social-graph element,such as a user node 202, a concept node 204, or an edge 206 of socialgraph 200. The probability score may indicate the level of similarity orrelevance between the n-gram and a particular social-graph element.There may be many different ways to calculate the probability. Thepresent disclosure contemplates any suitable method to calculate aprobability score for an n-gram identified in a search query. Inparticular embodiments, the mobile client system 130 may determine aprobability, p, that an n-gram corresponds to a particular social-graphelement. The probability, p, may be calculated as the probability ofcorresponding to a particular social-graph element, k, given aparticular search query, X. In other words, the probability may becalculated as p=(k|X). As an example and not by way of limitation, aprobability that an n-gram corresponds to a social-graph element maycalculated as an probability score denoted as p_(i,j,k). The input maybe a text query X=(x₁, x₂, . . . , x_(N)), and a set of classes. Foreach (i:j) and a class k, the mobile client system 130 may computep_(i,j,k)=p(class(x_(i:j))=k|X). As an example and not by way oflimitation, the n-gram “stanford” could be scored with respect to thefollowing social-graph elements as follows: school “StanfordUniversity”=0.7; location “Stanford, California”=0.2; user “AllenStanford”=0.1. As another example and not by way of limitation, then-gram “friends” could be scored with respect to the followingsocial-graph elements as follows: user “friends”=0.9; television show“Friends”=0.1. In particular embodiments, the mobile client system 130may use a forward-backward algorithm to determine the probability that aparticular n-gram corresponds to a particular social-graph element. Fora given n-gram within a text query, the mobile client system 130 may useboth the preceding and succeeding n-grams to determine which particularsocial-graph elements correspond to the given n-gram. In particularembodiments, the identified social-graph elements may be used togenerate a query command that is executable by a search engine. Thequery command may be a structured semantic query with defined functionsthat accept specific arguments. As an example and not by way oflimitation, the text query “friend me mark” could be parsed to form thequery command: intersect(friend(me), friend(Mark)). In other words, thequery is looking for nodes in the social graph that intersect thequerying user (“me”) and the user “Mark” (i.e., those user nodes 202that are connected to both the user node 202 of the querying user by afriend-type edge 206 and the user node 202 for the user “Mark” by afriend-type edge 206). Although this disclosure describes determiningwhether n-grams correspond to social-graph elements in a particularmanner, this disclosure contemplates determining whether n-gramscorrespond to social-graph elements in any suitable manner. Moreover,although this disclosure describes determining whether an n-gramcorresponds to a social-graph element using a particular type of score,this disclosure contemplates determining whether an n-gram correspondsto a social-graph element using any suitable type of score.

In particular embodiments, mobile client system 130 may identify one ormore edges 206 having a probability greater than an edge-thresholdprobability. Each of the identified edges 206 may correspond to at leastone of the n-grams. As an example and not by way of limitation, then-gram may only be identified as corresponding to an edge, k, ifp_(i,j,k)>p_(edge-threshold). Furthermore, each of the identified edges206 may be connected to at least one of the identified nodes. In otherwords, the mobile client system 130 may only identify edges 206 oredge-types that are connected to user nodes 202 or concept nodes 204that have previously been identified as corresponding to a particularn-gram. Edges 206 or edge-types that are not connected to any previouslyidentified node are typically unlikely to correspond to a particularn-gram in a search query. By filtering out or ignoring these edges 206and edge-types, the mobile client system 130 may more efficiently searchthe social graph 200 for relevant social-graph elements. As an exampleand not by way of limitation, referencing FIG. 2, for a text querycontaining “went to Stanford,” where an identified concept node 204 isthe school “Stanford,” the mobile client system 130 may identify theedges 206 corresponding to “worked at” and the edges 206 correspondingto “attended,” both of which are connected to the concept node 204 for“Stanford.” Thus, the n-gram “went to” may be identified ascorresponding to these edges 206. However, for the same text query, themobile client system 130 may not identify the edges 206 corresponding to“like” or “fan” in the social graph 200 because the “Stanford” node doesnot have any such edges connected to it. Although this disclosuredescribes identifying edges 206 that correspond to n-grams in aparticular manner, this disclosure contemplates identifying edges 206that correspond to n-grams in any suitable manner.

In particular embodiments, mobile client system 130 may identify one ormore user nodes 202 or concept nodes 204 having a probability greaterthan a node-threshold probability. Each of the identified nodes maycorrespond to at least one of the n-grams. As an example and not by wayof limitation, the n-gram may only be identified as corresponding to anode, k, if p_(i,j,k)>p_(node-threshold). Furthermore, each of theidentified user nodes 202 or concept nodes 204 may be connected to atleast one of the identified edges 206. In other words, the mobile clientsystem 130 may only identify nodes or nodes-types that are connected toedges 206 that have previously been identified as corresponding to aparticular n-gram. Nodes or node-types that are not connected to anypreviously identified edges 206 are typically unlikely to correspond toa particular n-gram in a search query. By filtering out or ignoringthese nodes and node-types, the mobile client system 130 may moreefficiently search the social graph 200 for relevant social-graphelements. As an example and not by way of limitation, for a text querycontaining “worked at Apple,” where an identified edge 206 is “workedat,” the mobile client system 130 may identify the concept node 204corresponding to the company APPLE, INC., which may have multiple edges206 of “worked at” connected to it. However, for the same text query,the mobile client system 130 may not identify the concept node 204corresponding to the fruit-type “apple,” which may have multiple “like”or “fan” edges connected to it, but no “worked at” edge connections. Inparticular embodiments, the node-threshold probability may differ foruser nodes 202 and concept nodes 204, and may differ even among thesenodes (e.g., some concept nodes 204 may have different node-thresholdprobabilities than other concept nodes 204). As an example and not byway of limitation, an n-gram may be identified as corresponding to auser node 302, k_(user), if p_(i,j,k)>p_(user-node-threshold) while ann-gram may be identified as corresponding to a concept node 304,k_(concept), if p_(i,j,k)>p_(concept-node-threshold). In particularembodiments, the mobile client system 130 may only identify nodes thatare within a threshold degree of separation of the user node 202corresponding to the first user (i.e., the querying user). The thresholddegree of separation may be, for example, one, two, three, or all.Although this disclosure describes identifying nodes that correspond ton-grams in a particular manner, this disclosure contemplates identifyingnodes that correspond to n-grams in any suitable manner.

In particular embodiments, the mobile client system 130 may access aplurality of grammar templates. Each grammar template may comprise oneor more non-terminal tokens (or “non-terminal symbols”) and one or moreterminal tokens (or “terminal symbols”/“query tokens”), where particularnon-terminal tokens may be replaced by terminal tokens. A grammar modelis a set of formation rules for strings in a formal language. Althoughthis disclosure describes accessing particular grammar templates, thisdisclosure contemplates any suitable grammars.

In particular embodiments, the mobile client system 130 may generate oneor more strings using one or more grammar templates. The non-terminalsymbols may be replaced with terminal symbols (i.e., terminal tokens orquery tokens). Some of the query tokens may correspond to identifiednodes or identified edges, as described previously. A string generatedby the grammar template may then be used as the basis for a structuredquery containing references to the identified nodes or identified edges.The string generated by the grammar may be rendered in anatural-language syntax, such that a structured query based on thestring is also rendered in natural language. A context-free grammar is agrammar in which the left-hand side of each production rule consists ofonly a single non-terminal symbol. A probabilistic context-free grammaris a tuple

Σ, N, S, P

, where the disjoint sets Σ and N specify the terminal and non-terminalsymbols, respectively, with SεN being the start symbol. P is the set ofproductions, which take the form E→ξ(p), with EεN, ξε(Σ∪N)⁺, andp=Pr(E→ξ), the probability that E will be expanded into the string ξ.The sum of probabilities p over all expansions of a given non-terminal Emust be one. Although this disclosure describes generating strings in aparticular manner, this disclosure contemplates generating strings inany suitable manner.

In particular embodiments, the mobile client system 130 may identify oneor more query tokens corresponding to the previously identified nodesand edges. In other words, if an identified node or identified edge maybe used as a query token in a particular grammar template, that querytoken may be identified by the mobile client system 130. As an exampleand not by way of limitation, an example grammar template may be:[user][user-filter][school]. The non-terminal tokens [user],[user-filter], and [school] could then be determined based n-grams inthe received text query. For the text query “friends stanford”, thisquery could be parsed by using the grammar template as, for example,“[friends][who go to][Stanford University]” or “[friends][who workat][Stanford University]”. As another example and not by way oflimitation, an example grammar template may be[user][user-filter][location]. For the text query “friends stanford”,this query could be parsed by using the grammar template, for example,“[friends][who live in][Stanford, California]”. In both the examplecases above, if the n-grams of the received text query could be used asquery tokens, then these query tokens may be identified by the mobileclient system 130. Although this disclosure describes identifyingparticular query tokens in a particular manner, this disclosurecontemplates identifying any suitable query tokens in any suitablemanner.

In particular embodiments, when the user inputs one or more textcharacters in search-query field 350, a program or application executedon mobile client system 130 may match the text characters againstgrammar templates pre-loaded on mobile client system 130. As describedbelow, mobile client system 130 may then search a data store of mobileclient system 130 to access grammar templates to determine one or morematches the query. As an example and not by way of limitation, theapplication executed on mobile client system 130 may perform thematching of the inputted text characters to the grammar templates aftereach keystroke. As another example, the inputted text may be parsed intoone or more n-grams, described above. In particular embodiments, thematching may be part of a client-side typeahead process. In particularembodiments, mobile client system 130 may identify one or morestructured queries based at least in part on matching input text to oneor more grammar templates or data identifying social-graph entities thatare stored on mobile client system 130.

In particular embodiments, the mobile client system 130 may select oneor more grammar templates having at least one query token correspondingto each of the previously identified nodes and edges. Only particulargrammar templates may be used depending on the n-grams identified in thetext query. So the terminal tokens of all available grammar templatesshould be examined to find those that match the identified n-grams fromthe text query. In other words, if a particular grammar template can useall of the identified nodes and edges as query tokens, that grammartemplate may be selected by the mobile client system 130 as a possiblegrammar template to use for generating a structured query. This iseffectively a type of bottom-up parsing, where the possible query tokensare used to determine the applicable grammar template to apply to thequery. As an example and not by way of limitation, for the text query“friends stanford”, mobile client system 130 may identify the querytokens of [friends] and [Stanford University]. Terminal tokens of thegrammar templates may be identified, as previously discussed. Anygrammar template that is able to use both the [friends] and the[Stanford University] tokens may then be selected. For example, thegrammar template [user] [user-filter] [school] may be selected becausethis grammar template could use the [friends] and the [StanfordUniversity] tokens as query tokens, such as by forming the strings“friends who go to Stanford University” or “friends who work at StanfordUniversity”. Thus, if the n-grams of the received text query could beused as query tokens in the grammar templates, then these grammartemplates may be selected by the mobile client system 130. Similarly, ifthe received text query comprises n-grams that could not be used asquery tokens in the grammar, that grammar may not be selected. Althoughthis disclosure describes selecting particular grammar templates in aparticular manner, this disclosure contemplates selecting any suitablegrammar templates in any suitable manner.

In particular embodiments, the mobile client system 130 may determine ascore for each selected grammar template. The score may be, for example,a confidence score, a probability, a quality, a ranking, anothersuitable type of score, or any combination thereof. The score may bebased on the individual scores or probabilities associated with thequery tokens used in the selected grammar. A grammar may have a higherrelative score if it uses query tokens with relatively higher individualscores. As an example and not by way of limitation, continuing with theprior examples, the n-gram “stanford” could be scored with respect tothe following social-graph elements as follows: school “StanfordUniversity”=0.7; location “Stanford, California”=0.2; user “AllenStanford”=0.1. The n-gram “friends” could be scored with respect to thefollowing social-graph elements as follows: user “friends”=0.9;television show “Friends”=0.1. Thus, the grammar template [user][user-filter] may have a relatively high score if it uses the querytokens for the user “friends” and the school “Stanford University”(generating, for example, the string “friends who go to StanfordUniversity”), both of which have relatively high individual scores. Incontrast, the grammar [user][user-filter][user] may have relatively lowscore if it uses the query tokens for the user “friends” and the user“Allen Stanford” (generating, for example, the string “friends of AllenStanford”), since the latter query token has a relatively low individualscore. Although this disclosure describes determining particular scoresfor particular grammars in a particular manner, this disclosurecontemplates determining any suitable scores for any suitable grammarsin any suitable manner.

In particular embodiments, the mobile client system 130 may determinethe score for a selected grammar template based on the relevance of thesocial-graph elements corresponding to the query tokens of the grammartemplate to the querying user (i.e., the first user, corresponding to afirst user node 202). User nodes 202 and concept nodes 204 that areconnected to the first user node 202 directly by an edge 206 may beconsidered relevant to the first user. Thus, grammar templatescomprising query tokens corresponding to these relevant nodes and edgesmay be considered more relevant to the querying user. As an example andnot by way of limitation, a concept node 204 connected by an edge 206 toa first user node 202 may be considered relevant to the first user node202. As used herein, when referencing a social graph 200 the term“connected” means a path exists within the social graph 200 between twonodes, wherein the path may comprise one or more edges 206 and zero ormore intermediary nodes. In particular embodiments, nodes that areconnected to the first user node 202 via one or more intervening nodes(and therefore two or more edges 206) may also be considered relevant tothe first user. Furthermore, in particular embodiments, the closer thesecond node is to the first user node, the more relevant the second nodemay be considered to the first user node. That is, the fewer edges 206separating the first user node 202 from a particular user node 202 orconcept node 204 (i.e., the fewer degrees of separation), the morerelevant that user node 202 or concept node 204 may be considered to thefirst user. As an example and not by way of limitation, as illustratedin FIG. 2, the concept node 204 corresponding to the school “Stanford”is connected to the user node 202 corresponding to User “C,” and thusthe concept “Stanford” may be considered relevant to User “C.” Asanother example and not by way of limitation, the user node 202corresponding to User “A” is connected to the user node 202corresponding to User “C” via one intermediate node and two edges 206(i.e., the intermediated user node 202 corresponding to User “B”), andthus User “A” may be considered relevant to User “C,” but because theuser node 202 for User “A” is a second-degree connection with respect toUser “C,” that particular concept node 204 may be considered lessrelevant than a user node 202 that is connected to the user node forUser “C” by a single edge 206, such as, for example, the user node 202corresponding to User “B.” As yet another example and not by way oflimitation, the concept node for “Online Poker” (which may correspond toan online multiplayer game) is not connected to the user node for User“C” by any pathway in social graph 200, and thus the concept “OnlinePoker” may not be considered relevant to User “C.” In particularembodiments, a second node may only be considered relevant to the firstuser if the second node is within a threshold degree of separation ofthe first user node 202. As an example and not by way of limitation, ifthe threshold degree of separation is three, then the user node 202corresponding to User “D” may be considered relevant to the concept node204 corresponding to the recipe “Chicken Parmesan,” which are withinthree degrees of each other on social graph 200 illustrated in FIG. 2.However, continuing with this example, the concept node 204corresponding to the application “All About Recipes” would not beconsidered relevant to the user node 202 corresponding to User “D”because these nodes are four degrees apart in the social graph 200.Although this disclosure describes determining whether particularsocial-graph elements (and thus their corresponding query tokens) arerelevant to each other in a particular manner, this disclosurecontemplates determining whether any suitable social-graph elements arerelevant to each other in any suitable manner. Moreover, although thisdisclosure describes determining whether particular query tokenscorresponding to user nodes 202 and concept nodes 204 are relevant to aquerying user, this disclosure contemplates similarly determiningwhether any suitable query token (and thus any suitable node) isrelevant to any other suitable user.

In particular embodiments, the mobile client system 130 may determinethe score for a selected grammar template based social-graph informationcorresponding to the query tokens of the grammar. As an example and notby way of limitation, when determining a probability, p, that an n-gramcorresponds to a particular social-graph element, the calculation of theprobability may also factor in social-graph information. Thus, theprobability of corresponding to a particular social-graph element, k,given a particular search query, X, and social-graph information, G, maybe calculated as p=(k|X, G). The individual probabilities for theidentified nodes and edges may then be used to determine the score for agrammar template using those social-graph elements as query tokens. Inparticular embodiments, the score for a selected grammar may be based onthe degree of separation between the first user node 202 and theparticular social-graph element used as a query token in the grammartemplate. Grammar templates with query tokens corresponding tosocial-graph elements that are closer in the social graph 200 to thequerying user (i.e., fewer degrees of separation between the element andthe first user node 202) may be scored more highly than grammars usingquery tokens corresponding to social-graph elements that are furtherfrom the user (i.e., more degrees of separation). As an example and notby way of limitation, referencing FIG. 2, if user “B” inputs a textquery of “chicken,” a grammar with a query token corresponding to theconcept node 204 for the recipe “Chicken Parmesan,” which is connectedto user “B” by an edge 206, may have a relatively higher score than agrammar template with a query token corresponding to other nodesassociated with the n-gram chicken (e.g., concept nodes 204corresponding to “chicken nuggets,” or “funky chicken dance”) that arenot connected to user “B” in the social graph 200. In particularembodiments, the score for a selected grammar template may be based onthe identified edges 206 corresponding to the query tokens of thegrammar template. If the mobile client system 130 has already identifiedone or more edges that correspond to n-grams in a received text query,those identified edges may then be considered when determining the scorefor a particular parsing of the text query by the grammar template. If aparticular grammar template comprises query tokens that correspond toboth identified nodes and identified edges, if the identified nodes arenot actually connected to any of the identified edges, that particulargrammar template may be assigned a zero or null score. In particularembodiments, the score for a selected grammar template may be based onthe number of edges 206 connected to the nodes corresponding to querytokens of the grammar template. Grammar templates comprising querytokens that corresponding to nodes with more connecting edges 206 may bemore popular and more likely to be a target of a search query. As anexample and not by way of limitation, if the concept node 204 for“Stanford, California” is only connected by five edges while the conceptnode 204 for “Stanford University” is connected by five-thousand edges,when determining the score for grammars containing query tokenscorresponding to either of these nodes, the mobile client system 130 maydetermine that the grammar template with a query token corresponding tothe concept node 204 for “Stanford University” has a relatively higherscore than a grammar template referencing the concept node 204 for“Stanford, California” because of the greater number of edges connectedto the former concept node 204. In particular embodiments, the score fora selected grammar may be based on the search history associate with thefirst user (i.e., the querying user). Grammar templates with querytokens corresponding to nodes that the first user has previouslyaccessed, or are relevant to the nodes the first user has previouslyaccessed, may be more likely to be the target of the first user's searchquery. Thus, these grammar templates may be given a higher score. As anexample and not by way of limitation, if first user has previouslyvisited the “Stanford University” profile page but has never visited the“Stanford, California” profile page, when determining the score forgrammar templates with query tokens corresponding to these concepts, themobile client system 130 may determine that the concept node 204 for“Stanford University” has a relatively high score, and thus the grammartemplate using the corresponding query token, because the querying userhas previously accessed the concept node 204 for the school. As anotherexample and not by way of limitation, if the first user has previouslyvisited the concept-profile page for the television show “Friends,” whendetermining the score for the grammar template with the query tokencorresponding to that concept, the mobile client system 130 maydetermine that the concept node 204 corresponding to the television show“Friends” has a relatively high score, and thus the grammar templateusing the corresponding query token, because the querying user haspreviously accessed the concept node 204 for that television show.Although this disclosure describes determining scores for particulargrammar templates based on particular social-graph information in aparticular manner, this disclosure contemplates determining scores forany suitable grammar templates based on any suitable social-graphinformation in any suitable manner.

FIGS. 6-8 illustrate graphical representations of example costcalculations for matching text inputs to grammar templates andsocial-graph entities. In particular embodiments, mobile client system130 may generate one or more structured queries based on selecting oneor more grammar templates or stored social-graph entities. Herein,reference to a query or terminal token may refer to one or moreidentified social-graph elements. Herein, reference to a non-terminaltoken may refer to a token of a structured query that may be matched toone or more social-graph entities. In particular embodiments, one ormore grammar templates may be based on a natural-language string andstored in a data store of mobile client system 130. A type of eachstored social-graph entity may be used to determine the relevance of thestored social-graph entity to a particular non-terminal token of one ormore grammar templates. In particular embodiments, the mobile clientsystem 130 may select one or more grammar templates based at least inpart on calculating a cost for each grammar template in relation to then-grams identified in the text query. As described above, a grammartemplate may include one or more non-terminal tokens and one or moreterminal tokens (also referred to as query tokens). For example, for agrammar template “Photos of [user] in [city]”, the non-terminal tokensare [user] and [city], while the query tokens are “Photos of” and “in”.The non-terminal tokens may be matched to social-graph entities, andreferences to those matching entities may be inserted into the grammartemplate in order to form a completed structured query (e.g., “Photos ofJustin in San Francisco”). In particular embodiments, n-grams that arematched as a query token to a non-terminal token may not incur theassociated insertion cost in the cost calculation. As an example and notby way of limitation, the n-gram “m” may be matched to query token [my]based at least in part on at a partial character matching of thecharacter “m” in n-gram “m” to query token [my]. Otherwise, when aparticular non-terminal token of the grammar templates does not matchany of the text characters, the insertion cost associated with theparticular non-terminal token in the cost calculation is incurred. Inparticular embodiments, a pre-determined number of social-graph entitiesmay be stored on mobile client system 130 and each stored social-graphentity may correspond to a query token of one or more of the grammartemplates. Furthermore, storing the social-graph entities on mobileclient system 130 may include data identifying the social-graph (e.g. atext string or title describing the social-graph entity), data uniquelyidentifying the social-graph entity to a particular system (e.g. anidentification number or string), a type associated with thesocial-graph entity (e.g. users or event), or any combination thereof.For example, data identifying the social-graph entity to the particularsystem may include an identification character string or a linkreferencing the social-graph entity. Although this disclosure describesgenerating structured queries in a particular manner, this disclosurecontemplates generating structured queries in any suitable manner.

In particular embodiments, the social-graph entities stored on mobileclient system 130 may be determined by pre-selecting particular types ofsocial-graph entities (e.g. popular entities). As an example, thesocial-graph entities of each user stored on mobile client system 130may correspond to friends of the user, pages of the user, groups of theuser, events of the user, applications installed by the user on mobileclient system 130, or any combination thereof. For example, pages of theuser may include entities associated with the user, such as for examplethe hometown, alma mater, employer, etc. of the user. In particularembodiments, the pre-determined number of social-graph entities may befirst-degree social-graph entities (e.g. concept nodes 204 or user nodes202 connected to the user node 202 of the user by an edge 206) or highcoefficient entities of each user.

In particular embodiments, the grammar templates may be based on anatural-language string, such as for example, “friends of [user]” or“friends who live near [city]”. One or more grammar templates stored ina data store of mobile client system 130 may be identified/constructedbased at least in part on an analysis of search queries performed onsocial-networking system 160 (e.g. through deconstruction of popularGraph Search queries). As an example and not by way of limitation, a logof search queries on social-networking system 160 may be analyzed toidentify a pre-determined number of the most popular search queries. Asanother example, a ranking of the identified search queries may bepersonalized for each user based at least in part on a search queryhistory of each user. In particular embodiments, the identified searchqueries may be converted into grammar templates as natural-languagestrings without one or more social-graph entities associated with thesearch queries, which may instead by substituted with non-terminaltokens in the grammar template.

In particular embodiments, the type of each stored social-graph entitymay be used to determine the relevance of the stored social-graph entityto a particular non-terminal token of one or more grammar templates. Asan example and not by way of limitation, the type of stored social-graphentity relevant to grammar template “photos of [user]” may be a typethat corresponds to friends of the user. As another example, the type ofsocial-graph entity relevant to a non-terminal token [location] may be atype that corresponds to pages (e.g. hometown) of the user. Furthermore,the grammar templates and data associated with social-graph entities maybe sent to and pre-loaded on mobile client system 130 prior to the userinputting text in search-query field 350. In particular embodiments, thepre-defined grammar templates and social-graph entities for each usermay be re-evaluated and updated by social-networking system 160 atpre-determined intervals (e.g. once a week). As an example and not byway of limitation, social-networking system 160 may send the updatedgrammar templates or data identifying the social-graph entities at thepre-determined intervals to mobile client system 130.

In particular embodiments, a client-side typeahead process of mobileclient system 130 may identify one or more structured queries matchingthe text input based at least in part on calculating a cost associatedwith each stored grammar template. As an example and not by way oflimitation, each stored grammar template may have a base cost.Furthermore, the base cost of each stored grammar template may beinversely proportional to the popularity of the search query that is thebasis of each pre-defined grammar templates. In other words, grammartemplates derived from more popular search queries may have a lowerassociated base cost. In particular embodiments, each non-terminal tokenof each grammar template may have an associated insertion cost. As anexample and not by way of limitation, the insertion cost of eachnon-terminal token may be related to an amount of differentiationprovided by the particular non-terminal token to the associatedpre-defined grammar template. For example, for a grammar template“photos of my friends,” the terminal token that corresponds to “friends”may have a higher insertion cost while the tokens that correspond to“of” or “my” that may be considered to be more generic and have less ofa contribution to identifying particular grammar templates. Inparticular embodiments, n-grams that are matched as a query token to anon-terminal token may not incur the associated insertion cost in thecost calculation. However, when a particular non-terminal token of thegrammar templates does not match any of the text characters, theinsertion cost associated with the particular non-terminal token in thecost calculation is incurred. In particular embodiments, one or more thesocial-graph entities associated with particular non-terminal tokens mayeach have an associated insertion cost.

As an example and not by way of limitation, text input “photo m” insearch-query field 350 may be partitioned into n-grams “photo” and “m,”and matched to grammar templates “photos of my friends” and “photos ofmy friends who work at [employer],” where [employer] is a non-terminaltoken that may associated with one or more of the stored social-graphentities, as described below. Furthermore, one or more social-graphentities may be identified as being relevant to non-terminal tokensbased on the type of the social-graph entity. As described above, theclient-side typeahead process may parse text input “photo m” into an-grams “photo” and “m.” As illustrated in the example of FIG. 6,grammar template 610 “photos of my friends” may be evaluated withrespect to n-grams “photo” and “m.” As an example and not by way oflimitation, the pre-defined grammar template 610 “photos of my friends”when completely matched may have query tokens [photos], [of], [my], and[friends] or otherwise incur an insertion cost, as described above.Initially, n-gram “photo” may be matched as a query token [photo] ofgrammar template 610 that corresponds to a stored social-graph entityand incurs no cost in the cost calculation, as illustrated by 620. Themodified typeahead process on the mobile client system 130 may evaluatethe remaining non-terminal tokens of grammar template 610 to theremainder of the inputted text characters. As illustrated by 630, then-gram “m” does not match query token [of]. As a result, the costcalculation incurs the insertion cost associated with not matching thequery token [of]. As illustrated by 640, the n-gram “m” may be matchedas a query token [my] and as a result does not incur any insertion cost.As an example and not by way of limitation, n-gram “m” may be matched toquery token [my] based at least in part on at a partial charactermatching of the character “m” in n-gram “m” to query token [my].Although this disclosure describes determining a match betweenparticular n-grams and particular query tokens based on particularcriterion, this disclosure contemplates determining a match between anysuitable n-grams and any suitable query token based on any suitablecriteria such as for example, a confidence score, a probability, aquality, a ranking, or any combination thereof. Since there are noremaining text characters, the insertion cost associated with theunmatched query token [friends] is incurred, as illustrated by 650.Assuming, the base cost of grammar template 610 “photos of my friends”is 1.1 and the insertion costs of the unmatched query tokens “photos,”“of,” “my,” “friends” are 2.2, 0.5, 0, and 1.5 respectively, thecalculated cost is 3.1 for structured search query “photos of myfriends.”

As illustrated in the example of FIG. 7, a grammar template 710 “photosof my friends who work at [employer]” may be evaluated with respect toinputted text “photo m.” As an example and not by way of limitation,grammar template 710 when completely matched may have query tokens[photos], [of], [my], [friends], [who], [work], [at] and non-terminaltoken [employer] that is evaluated with the social-graph entity“Facebook” that corresponds to the lowest cost stored social-graphentity of type “employer.” Initially, the n-gram “photo” may be matchedas a query token [photo] of grammar template 710 and incurs no cost inthe cost calculation, as illustrated by 720. The remaining non-terminaltokens of the pre-defined grammar template may be evaluated against theremaining n-gram. As illustrated by 730, the n-gram “m” does not matchas a query token [of]. As a result, the cost calculation incurs theinsertion cost associated with the n-gram not matching to query token[of]. As illustrated by 740, the n-gram “m” matches as a query token[my] and as a result does not incur any insertion cost. As describedabove, n-gram “m” may be matched to query token [my] based at least inpart on at a partial character matching of the character “m” in n-gram“m” to query token [my]. Since there are no remaining text characters,the insertion cost associated with not matching query token [friends],[who], [work], and [at] are incurred, as illustrated by 750-790.Assuming, the base cost of grammar template 710 “photos of my friendswho work at [employer]” is 2.1 and the insertion costs of thenon-terminal tokens when not matched as query tokens [photos] [of] [my][friends] [who], [work], [at], and [employer] are 2.2, 0.5, 0, 1.5, 0.1,0.3, 0.5, and 1.0, respectively. And assuming the insertion cost ofsocial-graph entity “Facebook” is 0.03, the resultant calculated cost is6.03 for structured search query “photos of my friends who work atFacebook.”

As illustrated in the example of FIG. 8, a grammar template 810 “photosof my friends who work at [employer]” with social-graph entity“Microsoft” may be evaluated with respect to inputted text “photo m.” Asdescribed above, the n-gram “photo” may be matched as a query token[photo] of grammar template 810 and incurs no cost in the costcalculation, as illustrated by 820. The remaining non-terminal tokens ofthe pre-defined grammar template may be evaluated against the remainingn-gram. As illustrated by 830, the n-gram “m” does not match as a querytoken [of]. As a result, the cost calculation incurs the insertion costassociated with not matching query token [of]. In particularembodiments, when the client-side typeahead process matches more thanone query token, the client-side typeahead process may match the n-gramto the higher insertion cost query token. As an example and not by wayof limitation, assuming non-terminal token [employer], social-graphentity “Microsoft,” and query token [my] when unmatched have insertioncosts of 1.0, 0.04, and 0, respectively, the client-side typeaheadprocess may match the n-gram “m” to non-terminal token [employer] andthe social-graph entity “Microsoft” while not matching as query token[my], as illustrated by 840 and 890. As an example and not by way oflimitation, n-gram “m” may be matched to non-terminal token [employer]evaluated with social-graph entity “Microsoft” based at least in part onat a partial character matching of the character “m” in n-gram “m” tosocial-graph entity “Microsoft.” Furthermore, [employer] evaluated withsocial-graph entity “Microsoft” is a non-terminal token corresponding toa matched social-graph entity (e.g. “Microsoft”). As a result, the costcalculation does not incur any insertion cost associated with thenon-terminal token [employer] or social-graph entity “Microsoft” andincurs the insertion cost associated with not matching query token [my].Since there are no remaining n-grams, the insertion cost associated withnot matching query tokens [friends], [who], [work], and [at] areincurred, as illustrated by 850-880. Assuming, the base cost of grammartemplate 810 “photos of my friends who work at [employer]” is 2.1 theinsertion costs of not matching query tokens [photos], [of], [my],[friends], [who], [work], [at], and [employer] are 2.2, 0.5, 0, 1.5,0.1, 0.3, 0.5, and 1.0, respectively. And assuming the insertion cost ofsocial-graph entity “Microsoft” is 0.04, the resultant calculated costis 5.04 for structured search query “photos of my friends who work atMicrosoft.”

In particular embodiments, mobile client system 130 may generate one ormore structured queries corresponding to the selected grammar templates(e.g., those grammar templates having a score greater than agrammar-threshold score). Each structured query may be based on a stringgenerated by the corresponding selected grammar template. As an exampleand not by way of limitation, in response to the text query “photo m”,the grammar [objects][user-filter][user][user] may generate a string“photos of my friends”, where the non-terminal tokens [objects],[user-filter], [user] of the grammar have been replaced by the querytokens [photos], [of], [my], and [friends], respectively, to generatethe string. In particular embodiments, a string that is generated bygrammar using a natural-language syntax may be rendered as a structuredquery in natural language. As an example and not by way of limitation,the structured query from the previous example uses the query token[of], which uses a natural-language syntax so that the string renderedby grammar is in natural language. The natural-language string generatedby a grammar may then be rendered to form a structured query bymodifying the query tokens corresponding to social-graph element toinclude references to those social-graph elements. As an example and notby way of limitation, the string “photos of my friends” may be renderedso that the query token for “friends” appears in the structured query asa reference to one or more second user nodes 202 corresponding to thefriends of the user, where the reference may be include highlighting, aninline link, a snippet, another suitable reference, or any combinationthereof. Each structured query may comprise query tokens correspondingto the corresponding selected grammar, where these query tokenscorrespond to one or more of the identified edges 206 and one or more ofthe identified nodes.

As described below, the client-side typeahead process may identify oneor more structured queries matching text input in search-query field350. In particular embodiments, the identified structured queries may beranked based at least in part on a calculated cost, described above. Asan example and not by way of limitation, the identified structuredqueries may be ranked based at least in part on the lowest calculatedcost. For example, based on the cost calculations described above, thestructured queries identified for text input “photo m” may have anexample ranking, from highest ranked to lowest, of “photos of myfriends,” “photos of my friends who work at Microsoft,” and “photos ofmy friends who work at Facebook.” Although this disclosure describesmatching and ranking particular text input to particular structuredqueries in a particular manner, this disclosure contemplates matchingand ranking any suitable text input to any suitable structured queriesin any suitable manner. More information on using grammar models withsearch queries may be found in U.S. patent application Ser. No.13/674,695, filed 12 Nov. 2012, which is incorporated by reference.

FIGS. 9-10 illustrate an example UI on an example mobile client systemwith example structured search queries. In particular embodiments, afterthe structured queries are identified, mobile client system 130 maydisplay one or more of the structured queries based on identifiedgrammar templates or stored social-graph entities. The structure queriesmay be displayed, for example, on a mobile web browser or UI of user'smobile client system 130 that may include, for example, the names (namestrings) of the referenced social-graph elements, other querylimitations (e.g., Boolean operators, etc.), as well as, potentially,other metadata associated with the referenced social-graph entities. Asan example and not by way of limitation, a mobile web browser or UI onthe querying user's mobile client system 130 may display the identifiedstructured queries in a drop-down menu 300, as illustrated in FIGS.9-10. A client-side typeahead process may match the text input insearch-query field 350 to the pre-defined grammar templates after eachkeystroke. In particular embodiments, as the user provides additionalcharacters in search-query field 350, the client-side typeahead processmay evaluate the additional text to update the structured queriespresented to the user in down-down menu 300. Furthermore, the user maythen click on or otherwise select (e.g., tapping on a selectedstructured query on a display of mobile client system 130) to indicatethe particular structured query the user wants the social-networkingsystem 160 to execute. In particular embodiments, the structured queriesmay be presented to the querying user in a ranked order, such as, forexample, based on a cost calculation previously determined as describedabove. Structured queries with higher rankings may be presented in amore prominent position. Furthermore, in particular embodiments, onlystructured queries with a cost calculation below a threshold cost valuemay be displayed to the querying user. As an example and not by way oflimitation, as illustrated in FIGS. 9-10, the structured queries may bepresented to the querying user in drop-down menu 300 where higher rankedstructured queries may be presented at the top of the menu, with lowerranked structured queries presented in descending order in drop-downmenu 300. In particular embodiments, one or more references in astructured query may be highlighted (e.g., outlined, underlined,circled, bolded, italicized, colored, lighted, offset, in caps) in orderto indicate its correspondence to a particular social-graph element.Furthermore, a graphical indicator that corresponds to a type of searchresults may be displayed with the structured queries in drop-down menu300. Although this disclosure describes displaying particular structuredqueries in a particular manner, this disclosure contemplates displayingany suitable structured queries in any suitable manner.

As described above, the client-side typeahead process may match the textinput in search-query field 350 to the pre-defined grammar templatesafter each keystroke. As a result, the identified structured queriesdisplayed in drop-down menu 300 may be updated after each keystroke. Inthe example illustrated in FIG. 9, drop-down menu 300 may display thesix highest ranked structured queries that match text input “photos.” Asthe user provides additional characters in search-query field 350, theclient-side typeahead process may evaluate the additional text to updatethe structured queries presented to the user in down-down menu 300. Inthe example illustrated in FIG. 10, drop-down menu 300 may display thesix highest ranked structured queries that match text input “photos ofmy.” As an example and not by way of limitation,

In particular embodiments, social-networking system 160 may receive fromthe querying user a selection of one of the structured queries indrop-down menu 300 from mobile client system 130. The nodes and edgesreferenced in the received structured query may be referred to as theselected nodes and selected edges, respectively. As an example and notby way of limitation, the web browser or UI on the querying user'smobile client system 130 may display the identified structured queriesin a drop-down menu 300, as described above, which the user may thenclick on or otherwise select (e.g., tapping on a selected structuredquery on a display of mobile client system 130) to indicate theparticular structured query the user wants the social-networking system160 to execute. As an example and not by way of limitation, referencingFIG. 10, the querying user may modify the input subsequent unstructuredtext query “photos of my” into search-query field 350. Mobile clientsystem 130 may modify the displayed structured queries based on theupdated n-grams and recalculated cost for each stored grammar templatebased on the update n-grams. Upon selecting the particular identifiedstructured query, the user's mobile client system 130 may call orotherwise instruct to the social-networking system 160 to execute theselected structured query. Although this disclosure describes receivingselections of particular structured queries in a particular manner, thisdisclosure contemplates receiving selections of any suitable structuredqueries in any suitable manner.

FIG. 11 illustrates an example method for generating client-sidestructured search queries. The method may begin at step 1110, where amobile client system may receive an unstructured text query from a firstuser of an online social network. At step 1120, one or more nodes of anumber of first nodes of a social graph of the online social network maybe accessed from a data store of the mobile client system. In particularembodiments, the social graph includes a number of nodes and a number ofedges connecting the nodes. Furthermore, each of the edges between twoof the nodes may represent a single degree of separation between them.In particular embodiments, the nodes may include first nodes that eachcorrespond to a concept or a second user associated with the onlinesocial network and a second node corresponding to the first user. Atstep 1130, a set of grammar templates may be accessed from the datastore of the mobile client system. In particular embodiments, eachgrammar template includes one or more non-terminal tokens and one ormore query tokens. As described above, query or terminal tokens maycorrespond to one or more identified social-graph elements. Furthermore,particular non-terminal tokens may be replaced in the grammar templateby one or more identified social-graph elements (e.g. query tokens). Inparticular embodiments, the query tokens include references to zero ormore second nodes and one or more edges. As an example and not by way oflimitation, each grammar template is based on a natural-language string.At step 1140, the mobile client system may generate one or morecompleted structured queries by matching the unstructured text query toone or more of the accessed nodes and one or more of the grammartemplates having non-terminal tokens corresponding to matched nodes. Asan example and not by way of limitation, matching the unstructured textquery to one or more of the grammar templates may be based at least inpart on a partial character match between one or more n-grams and one ormore query tokens of the grammar template. In particular embodiments,each structured query may include references to one or more of theaccessed nodes matched to the one or more non-terminal tokens and thezero or more second nodes and the one or more edges referenced in thecorresponding grammar template. At step 1150, the mobile client systemmay display one or more completed structured queries to the first user.Particular embodiments may repeat one or more steps of the method ofFIG. 11, where appropriate. Although this disclosure describes andillustrates particular steps of the method of FIG. 11 as occurring in aparticular order, this disclosure contemplates any suitable steps of themethod of FIG. 11 occurring in any suitable order. Moreover, althoughthis disclosure describes and illustrates particular components,devices, or systems carrying out particular steps of the method of FIG.11, this disclosure contemplates any suitable combination of anysuitable components, devices, or systems carrying out any suitable stepsof the method of FIG. 11.

Social Graph Affinity and Coefficient

In particular embodiments, social-networking system 160 may determinethe social-graph affinity (which may be referred to herein as“affinity”) of various social-graph entities for each other. Affinitymay represent the strength of a relationship or level of interestbetween particular objects associated with the online social network,such as users, concepts, content, actions, advertisements, other objectsassociated with the online social network, or any suitable combinationthereof. Affinity may also be determined with respect to objectsassociated with third-party systems 170 or other suitable systems. Anoverall affinity for a social-graph entity for each user, subjectmatter, or type of content may be established. The overall affinity maychange based on continued monitoring of the actions or relationshipsassociated with the social-graph entity. Although this disclosuredescribes determining particular affinities in a particular manner, thisdisclosure contemplates determining any suitable affinities in anysuitable manner.

In particular embodiments, social-networking system 160 may measure orquantify social-graph affinity using an affinity coefficient (which maybe referred to herein as “coefficient”). The coefficient may representor quantify the strength of a relationship between particular objectsassociated with the online social network. The coefficient may alsorepresent a probability or function that measures a predictedprobability that a user will perform a particular action based on theuser's interest in the action. In this way, a user's future actions maybe predicted based on the user's prior actions, where the coefficientmay be calculated at least in part on a history of the user's actions.Coefficients may be used to predict any number of actions, which may bewithin or outside of the online social network. As an example and not byway of limitation, these actions may include various types ofcommunications, such as sending messages, posting content, or commentingon content; various types of an observation actions, such as accessingor viewing profile pages, media, or other suitable content; varioustypes of coincidence information about two or more social-graphentities, such as being in the same group, tagged in the samephotograph, checked-in at the same location, or attending the sameevent; or other suitable actions. Although this disclosure describesmeasuring affinity in a particular manner, this disclosure contemplatesmeasuring affinity in any suitable manner.

In particular embodiments, social-networking system 160 may use avariety of factors to calculate a coefficient. These factors mayinclude, for example, user actions, types of relationships betweenobjects, location information, other suitable factors, or anycombination thereof. In particular embodiments, different factors may beweighted differently when calculating the coefficient. The weights foreach factor may be static or the weights may change according to, forexample, the user, the type of relationship, the type of action, theuser's location, and so forth. Ratings for the factors may be combinedaccording to their weights to determine an overall coefficient for theuser. As an example and not by way of limitation, particular useractions may be assigned both a rating and a weight while a relationshipassociated with the particular user action is assigned a rating and acorrelating weight (e.g., so the weights total 100%). To calculate thecoefficient of a user towards a particular object, the rating assignedto the user's actions may comprise, for example, 60% of the overallcoefficient, while the relationship between the user and the object maycomprise 40% of the overall coefficient. In particular embodiments, thesocial-networking system 160 may consider a variety of variables whendetermining weights for various factors used to calculate a coefficient,such as, for example, the time since information was accessed, decayfactors, frequency of access, relationship to information orrelationship to the object about which information was accessed,relationship to social-graph entities connected to the object, short- orlong-term averages of user actions, user feedback, other suitablevariables, or any combination thereof. As an example and not by way oflimitation, a coefficient may include a decay factor that causes thestrength of the signal provided by particular actions to decay withtime, such that more recent actions are more relevant when calculatingthe coefficient. The ratings and weights may be continuously updatedbased on continued tracking of the actions upon which the coefficient isbased. Any type of process or algorithm may be employed for assigning,combining, averaging, and so forth the ratings for each factor and theweights assigned to the factors. In particular embodiments,social-networking system 160 may determine coefficients usingmachine-learning algorithms trained on historical actions and past userresponses, or data farmed from users by exposing them to various optionsand measuring responses. Although this disclosure describes calculatingcoefficients in a particular manner, this disclosure contemplatescalculating coefficients in any suitable manner.

In particular embodiments, social-networking system 160 may calculate acoefficient based on a user's actions. Social-networking system 160 maymonitor such actions on the online social network, on a third-partysystem 170, on other suitable systems, or any combination thereof. Anysuitable type of user actions may be tracked or monitored. Typical useractions include viewing profile pages, creating or posting content,interacting with content, tagging or being tagged in images, joininggroups, listing and confirming attendance at events, checking-in atlocations, liking particular pages, creating pages, and performing othertasks that facilitate social action. In particular embodiments,social-networking system 160 may calculate a coefficient based on theuser's actions with particular types of content. The content may beassociated with the online social network, a third-party system 170, oranother suitable system. The content may include users, profile pages,posts, news stories, headlines, instant messages, chat roomconversations, emails, advertisements, pictures, video, music, othersuitable objects, or any combination thereof. Social-networking system160 may analyze a user's actions to determine whether one or more of theactions indicate an affinity for subject matter, content, other users,and so forth. As an example and not by way of limitation, if a user maymake frequently posts content related to “coffee” or variants thereof,social-networking system 160 may determine the user has a highcoefficient with respect to the concept “coffee”. Particular actions ortypes of actions may be assigned a higher weight and/or rating thanother actions, which may affect the overall calculated coefficient. Asan example and not by way of limitation, if a first user emails a seconduser, the weight or the rating for the action may be higher than if thefirst user simply views the user-profile page for the second user.

In particular embodiments, social-networking system 160 may calculate acoefficient based on the type of relationship between particularobjects. Referencing the social graph 200, social-networking system 160may analyze the number and/or type of edges 206 connecting particularuser nodes 202 and concept nodes 204 when calculating a coefficient. Asan example and not by way of limitation, user nodes 202 that areconnected by a spouse-type edge (representing that the two users aremarried) may be assigned a higher coefficient than a user nodes 202 thatare connected by a friend-type edge. In other words, depending upon theweights assigned to the actions and relationships for the particularuser, the overall affinity may be determined to be higher for contentabout the user's spouse than for content about the user's friend. Inparticular embodiments, the relationships a user has with another objectmay affect the weights and/or the ratings of the user's actions withrespect to calculating the coefficient for that object. As an exampleand not by way of limitation, if a user is tagged in first photo, butmerely likes a second photo, social-networking system 160 may determinethat the user has a higher coefficient with respect to the first photothan the second photo because having a tagged-in-type relationship withcontent may be assigned a higher weight and/or rating than having alike-type relationship with content. In particular embodiments,social-networking system 160 may calculate a coefficient for a firstuser based on the relationship one or more second users have with aparticular object. In other words, the connections and coefficientsother users have with an object may affect the first user's coefficientfor the object. As an example and not by way of limitation, if a firstuser is connected to or has a high coefficient for one or more secondusers, and those second users are connected to or have a highcoefficient for a particular object, social-networking system 160 maydetermine that the first user should also have a relatively highcoefficient for the particular object. In particular embodiments, thecoefficient may be based on the degree of separation between particularobjects. The lower coefficient may represent the decreasing likelihoodthat the first user will share an interest in content objects of theuser that is indirectly connected to the first user in the social graph200. As an example and not by way of limitation, social-graph entitiesthat are closer in the social graph 200 (i.e., fewer degrees ofseparation) may have a higher coefficient than entities that are furtherapart in the social graph 200.

In particular embodiments, social-networking system 160 may calculate acoefficient based on location information. Objects that aregeographically closer to each other may be considered to be more relatedor of more interest to each other than more distant objects. Inparticular embodiments, the coefficient of a user towards a particularobject may be based on the proximity of the object's location to acurrent location associated with the user (or the location of a clientsystem 130 of the user). A first user may be more interested in otherusers or concepts that are closer to the first user. As an example andnot by way of limitation, if a user is one mile from an airport and twomiles from a gas station, social-networking system 160 may determinethat the user has a higher coefficient for the airport than the gasstation based on the proximity of the airport to the user.

In particular embodiments, social-networking system 160 may performparticular actions with respect to a user based on coefficientinformation. Coefficients may be used to predict whether a user willperform a particular action based on the user's interest in the action.A coefficient may be used when generating or presenting any type ofobjects to a user, such as advertisements, search results, news stories,media, messages, notifications, or other suitable objects. Thecoefficient may also be utilized to rank and order such objects, asappropriate. In this way, social-networking system 160 may provideinformation that is relevant to user's interests and currentcircumstances, increasing the likelihood that they will find suchinformation of interest. In particular embodiments, social-networkingsystem 160 may generate content based on coefficient information.Content objects may be provided or selected based on coefficientsspecific to a user. As an example and not by way of limitation, thecoefficient may be used to generate media for the user, where the usermay be presented with media for which the user has a high overallcoefficient with respect to the media object. As another example and notby way of limitation, the coefficient may be used to generateadvertisements for the user, where the user may be presented withadvertisements for which the user has a high overall coefficient withrespect to the advertised object. In particular embodiments,social-networking system 160 may generate search results based oncoefficient information. Search results for a particular user may bescored or ranked based on the coefficient associated with the searchresults with respect to the querying user. As an example and not by wayof limitation, search results corresponding to objects with highercoefficients may be ranked higher on a search-results page than resultscorresponding to objects having lower coefficients.

In particular embodiments, social-networking system 160 may calculate acoefficient in response to a request for a coefficient from a particularsystem or process. To predict the likely actions a user may take (or maybe the subject of) in a given situation, any process may request acalculated coefficient for a user. The request may also include a set ofweights to use for various factors used to calculate the coefficient.This request may come from a process running on the online socialnetwork, from a third-party system 170 (e.g., via an API or othercommunication channel), or from another suitable system. In response tothe request, social-networking system 160 may calculate the coefficient(or access the coefficient information if it has previously beencalculated and stored). In particular embodiments, social-networkingsystem 160 may measure an affinity with respect to a particular process.Different processes (both internal and external to the online socialnetwork) may request a coefficient for a particular object or set ofobjects. Social-networking system 160 may provide a measure of affinitythat is relevant to the particular process that requested the measure ofaffinity. In this way, each process receives a measure of affinity thatis tailored for the different context in which the process will use themeasure of affinity.

In connection with social-graph affinity and affinity coefficients,particular embodiments may utilize one or more systems, components,elements, functions, methods, operations, or steps disclosed in U.S.patent application Ser. No. 11/503,093, filed 11 Aug. 2006, U.S. patentapplication Ser. No. 12/977,027, filed 22 Dec. 2010, U.S. patentapplication Ser. No. 12/978,265, filed 23 Dec. 2010, and U.S. patentapplication Ser. No. 13/632,869, filed 1 Oct. 2012, each of which isincorporated by reference.

Systems and Methods

FIG. 12 illustrates an example computer system 1200. In particularembodiments, one or more computer systems 1200 perform one or more stepsof one or more methods described or illustrated herein. In particularembodiments, one or more computer systems 1200 provide functionalitydescribed or illustrated herein. In particular embodiments, softwarerunning on one or more computer systems 1200 performs one or more stepsof one or more methods described or illustrated herein or providesfunctionality described or illustrated herein. Particular embodimentsinclude one or more portions of one or more computer systems 1200.Herein, reference to a computer system may encompass a computing device,and vice versa, where appropriate. Moreover, reference to a computersystem may encompass one or more computer systems, where appropriate.

This disclosure contemplates any suitable number of computer systems1200. This disclosure contemplates computer system 1200 taking anysuitable physical form. As example and not by way of limitation,computer system 1200 may be an embedded computer system, asystem-on-chip (SOC), a single-board computer system (SBC) (such as, forexample, a computer-on-module (COM) or system-on-module (SOM)), adesktop computer system, a laptop or notebook computer system, aninteractive kiosk, a mainframe, a mesh of computer systems, a mobiletelephone, a personal digital assistant (PDA), a server, a tabletcomputer system, or a combination of two or more of these. Whereappropriate, computer system 1200 may include one or more computersystems 1200; be unitary or distributed; span multiple locations; spanmultiple machines; span multiple data centers; or reside in a cloud,which may include one or more cloud components in one or more networks.Where appropriate, one or more computer systems 1200 may perform withoutsubstantial spatial or temporal limitation one or more steps of one ormore methods described or illustrated herein. As an example and not byway of limitation, one or more computer systems 1200 may perform in realtime or in batch mode one or more steps of one or more methods describedor illustrated herein. One or more computer systems 1200 may perform atdifferent times or at different locations one or more steps of one ormore methods described or illustrated herein, where appropriate.

In particular embodiments, computer system 1200 includes a processor1202, memory 1204, storage 1206, an input/output (I/O) interface 1208, acommunication interface 1210, and a bus 1212. Although this disclosuredescribes and illustrates a particular computer system having aparticular number of particular components in a particular arrangement,this disclosure contemplates any suitable computer system having anysuitable number of any suitable components in any suitable arrangement.

In particular embodiments, processor 1202 includes hardware forexecuting instructions, such as those making up a computer program. Asan example and not by way of limitation, to execute instructions,processor 1202 may retrieve (or fetch) the instructions from an internalregister, an internal cache, memory 1204, or storage 1206; decode andexecute them; and then write one or more results to an internalregister, an internal cache, memory 1204, or storage 1206. In particularembodiments, processor 1202 may include one or more internal caches fordata, instructions, or addresses. This disclosure contemplates processor1202 including any suitable number of any suitable internal caches,where appropriate. As an example and not by way of limitation, processor1202 may include one or more instruction caches, one or more datacaches, and one or more translation lookaside buffers (TLBs).Instructions in the instruction caches may be copies of instructions inmemory 1204 or storage 1206, and the instruction caches may speed upretrieval of those instructions by processor 1202. Data in the datacaches may be copies of data in memory 1204 or storage 1206 forinstructions executing at processor 1202 to operate on; the results ofprevious instructions executed at processor 1202 for access bysubsequent instructions executing at processor 1202 or for writing tomemory 1204 or storage 1206; or other suitable data. The data caches mayspeed up read or write operations by processor 1202. The TLBs may speedup virtual-address translation for processor 1202. In particularembodiments, processor 1202 may include one or more internal registersfor data, instructions, or addresses. This disclosure contemplatesprocessor 1202 including any suitable number of any suitable internalregisters, where appropriate. Where appropriate, processor 1202 mayinclude one or more arithmetic logic units (ALUs); be a multi-coreprocessor; or include one or more processors 1202. Although thisdisclosure describes and illustrates a particular processor, thisdisclosure contemplates any suitable processor.

In particular embodiments, memory 1204 includes main memory for storinginstructions for processor 1202 to execute or data for processor 1202 tooperate on. As an example and not by way of limitation, computer system1200 may load instructions from storage 1206 or another source (such as,for example, another computer system 1200) to memory 1204. Processor1202 may then load the instructions from memory 1204 to an internalregister or internal cache. To execute the instructions, processor 1202may retrieve the instructions from the internal register or internalcache and decode them. During or after execution of the instructions,processor 1202 may write one or more results (which may be intermediateor final results) to the internal register or internal cache. Processor1202 may then write one or more of those results to memory 1204. Inparticular embodiments, processor 1202 executes only instructions in oneor more internal registers or internal caches or in memory 1204 (asopposed to storage 1206 or elsewhere) and operates only on data in oneor more internal registers or internal caches or in memory 1204 (asopposed to storage 1206 or elsewhere). One or more memory buses (whichmay each include an address bus and a data bus) may couple processor1202 to memory 1204. Bus 1212 may include one or more memory buses, asdescribed below. In particular embodiments, one or more memorymanagement units (MMUs) reside between processor 1202 and memory 1204and facilitate accesses to memory 1204 requested by processor 1202. Inparticular embodiments, memory 1204 includes random access memory (RAM).This RAM may be volatile memory, where appropriate Where appropriate,this RAM may be dynamic RAM (DRAM) or static RAM (SRAM). Moreover, whereappropriate, this RAM may be single-ported or multi-ported RAM. Thisdisclosure contemplates any suitable RAM. Memory 1204 may include one ormore memories 1204, where appropriate. Although this disclosuredescribes and illustrates particular memory, this disclosurecontemplates any suitable memory.

In particular embodiments, storage 1206 includes mass storage for dataor instructions. As an example and not by way of limitation, storage1206 may include a hard disk drive (HDD), a floppy disk drive, flashmemory, an optical disc, a magneto-optical disc, magnetic tape, or aUniversal Serial Bus (USB) drive or a combination of two or more ofthese. Storage 1206 may include removable or non-removable (or fixed)media, where appropriate. Storage 1206 may be internal or external tocomputer system 1200, where appropriate. In particular embodiments,storage 1206 is non-volatile, solid-state memory. In particularembodiments, storage 1206 includes read-only memory (ROM). Whereappropriate, this ROM may be mask-programmed ROM, programmable ROM(PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM),electrically alterable ROM (EAROM), or flash memory or a combination oftwo or more of these. This disclosure contemplates mass storage 1206taking any suitable physical form. Storage 1206 may include one or morestorage control units facilitating communication between processor 1202and storage 1206, where appropriate. Where appropriate, storage 1206 mayinclude one or more storages 1206. Although this disclosure describesand illustrates particular storage, this disclosure contemplates anysuitable storage.

In particular embodiments, I/O interface 1208 includes hardware,software, or both, providing one or more interfaces for communicationbetween computer system 1200 and one or more I/O devices. Computersystem 1200 may include one or more of these I/O devices, whereappropriate. One or more of these I/O devices may enable communicationbetween a person and computer system 1200. As an example and not by wayof limitation, an I/O device may include a keyboard, keypad, microphone,monitor, mouse, printer, scanner, speaker, still camera, stylus, tablet,touch screen, trackball, video camera, another suitable I/O device or acombination of two or more of these. An I/O device may include one ormore sensors. This disclosure contemplates any suitable I/O devices andany suitable I/O interfaces 1208 for them. Where appropriate, I/Ointerface 1208 may include one or more device or software driversenabling processor 1202 to drive one or more of these I/O devices. I/Ointerface 1208 may include one or more I/O interfaces 1208, whereappropriate. Although this disclosure describes and illustrates aparticular I/O interface, this disclosure contemplates any suitable I/Ointerface.

In particular embodiments, communication interface 1210 includeshardware, software, or both providing one or more interfaces forcommunication (such as, for example, packet-based communication) betweencomputer system 1200 and one or more other computer systems 1200 or oneor more networks. As an example and not by way of limitation,communication interface 1210 may include a network interface controller(NIC) or network adapter for communicating with an Ethernet or otherwire-based network or a wireless NIC (WNIC) or wireless adapter forcommunicating with a wireless network, such as a WI-FI network. Thisdisclosure contemplates any suitable network and any suitablecommunication interface 1210 for it. As an example and not by way oflimitation, computer system 1200 may communicate with an ad hoc network,a personal area network (PAN), a local area network (LAN), a wide areanetwork (WAN), a metropolitan area network (MAN), or one or moreportions of the Internet or a combination of two or more of these. Oneor more portions of one or more of these networks may be wired orwireless. As an example, computer system 1200 may communicate with awireless PAN (WPAN) (such as, for example, a BLUETOOTH WPAN), a WI-FInetwork, a WI-MAX network, a cellular telephone network (such as, forexample, a Global System for Mobile Communications (GSM) network), orother suitable wireless network or a combination of two or more ofthese. Computer system 1200 may include any suitable communicationinterface 1210 for any of these networks, where appropriate.Communication interface 1210 may include one or more communicationinterfaces 1210, where appropriate. Although this disclosure describesand illustrates a particular communication interface, this disclosurecontemplates any suitable communication interface.

In particular embodiments, bus 1212 includes hardware, software, or bothcoupling components of computer system 1200 to each other. As an exampleand not by way of limitation, bus 1212 may include an AcceleratedGraphics Port (AGP) or other graphics bus, an Enhanced Industry StandardArchitecture (EISA) bus, a front-side bus (FSB), a HYPERTRANSPORT (HT)interconnect, an Industry Standard Architecture (ISA) bus, an INFINIBANDinterconnect, a low-pin-count (LPC) bus, a memory bus, a Micro ChannelArchitecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, aPCI-Express (PCIe) bus, a serial advanced technology attachment (SATA)bus, a Video Electronics Standards Association local (VLB) bus, oranother suitable bus or a combination of two or more of these. Bus 1212may include one or more buses 1212, where appropriate. Although thisdisclosure describes and illustrates a particular bus, this disclosurecontemplates any suitable bus or interconnect.

Herein, a computer-readable non-transitory storage medium or media mayinclude one or more semiconductor-based or other integrated circuits(ICs) (such, as for example, field-programmable gate arrays (FPGAs) orapplication-specific ICs (ASICs)), hard disk drives (HDDs), hybrid harddrives (HHDs), optical discs, optical disc drives (ODDs),magneto-optical discs, magneto-optical drives, floppy diskettes, floppydisk drives (FDDs), magnetic tapes, solid-state drives (SSDs),RAM-drives, SECURE DIGITAL cards or drives, any other suitablecomputer-readable non-transitory storage media, or any suitablecombination of two or more of these, where appropriate. Acomputer-readable non-transitory storage medium may be volatile,non-volatile, or a combination of volatile and non-volatile, whereappropriate.

Miscellaneous

Herein, “or” is inclusive and not exclusive, unless expressly indicatedotherwise or indicated otherwise by context. Therefore, herein, “A or B”means “A, B, or both,” unless expressly indicated otherwise or indicatedotherwise by context. Moreover, “and” is both joint and several, unlessexpressly indicated otherwise or indicated otherwise by context.Therefore, herein, “A and B” means “A and B, jointly or severally,”unless expressly indicated otherwise or indicated otherwise by context.

The scope of this disclosure encompasses all changes, substitutions,variations, alterations, and modifications to the example embodimentsdescribed or illustrated herein that a person having ordinary skill inthe art would comprehend. The scope of this disclosure is not limited tothe example embodiments described or illustrated herein. Moreover,although this disclosure describes and illustrates respectiveembodiments herein as including particular components, elements,functions, operations, or steps, any of these embodiments may includeany combination or permutation of any of the components, elements,functions, operations, or steps described or illustrated anywhere hereinthat a person having ordinary skill in the art would comprehend.Furthermore, reference in the appended claims to an apparatus or systemor a component of an apparatus or system being adapted to, arranged to,capable of, configured to, enabled to, operable to, or operative toperform a particular function encompasses that apparatus, system,component, whether or not it or that particular function is activated,turned on, or unlocked, as long as that apparatus, system, or componentis so adapted, arranged, capable, configured, enabled, operable, oroperative.

What is claimed is:
 1. A method comprising, by one or more processorsassociated with a mobile client system: receiving, at the mobile clientsystem, an unstructured text query from a first user of an online socialnetwork; parsing, by the mobile client system, the unstructured textquery into one or more n-grams; accessing, from a data store of themobile client system, a set of nodes of a social graph of the onlinesocial network, the social graph comprising a plurality of nodes and aplurality of edges connecting the nodes, the nodes comprising: a firstnode corresponding to the first user; and a plurality of second nodesthat each correspond to a concept or a second user associated with theonline social network; accessing, from the data store of the mobileclient system, a set of grammar templates, each grammar templatecomprising one or more non-terminal tokens and one or more query tokens,wherein the query tokens comprise references to zero or more secondnodes and one or more edges, and wherein each grammar template is basedon a natural-language string; generating, by the mobile client system,one or more structured queries by matching the unstructured text queryto one or more of the accessed nodes and one or more of the grammartemplates having non-terminal tokens corresponding to the matched nodes,each structured query comprising references to one or more of theaccessed nodes matched to the one or more non-terminal tokens and thezero or more of the second nodes and the one or more edges referenced inthe corresponding grammar template; calculating, by the mobile clientsystem, a cost for each grammar template based at least in part on oneor more of the n-grams not corresponding to one of the non-terminaltokens or query tokens; and displaying, at the mobile client system, oneor more structured queries to the first user; wherein each non-terminaltoken and query token has an associated insertion cost; and whereincalculating the cost comprises incurring an insertion cost for each ofthe non-terminal tokens or query tokens not corresponding to one or moren-grams.
 2. The method of claim 1, wherein the calculating the costcomprises identifying, by the mobile client system, a particularnon-terminal token from one or more of the non-terminal tokens thatcorrespond to a particular n-gram based at least in part on theinsertion cost of each non-terminal token.
 3. The method of claim 1,wherein the calculating the cost comprises: associating, by the mobileclient system, one of the accessed nodes to one of the non-terminaltokens; and incurring the insertion cost for the non-terminal token andthe associated accessed node based on the associated accessed node notcorresponding to one of the n-grams.
 4. The method of claim 1, furthercomprising ranking, by the mobile client system, one or more of thestructured queries based at least in part on the calculated cost of theassociated grammar template.
 5. The method of claim 1, wherein thecalculating the cost comprises incurring a base cost associated witheach grammar template, the base cost having an inverse relationship to apopularity measure associated with one or more search queries that are abasis of each grammar template.
 6. The method of claim 5, wherein thepopularity measure is based at least in part on a search-query historyof the first user.
 7. The method of claim 6, wherein the popularitymeasure is based at least in part on a search-query history of users ofthe online social network.
 8. The method of claim 1, wherein each of thedisplayed structured queries has a calculated cost below a thresholdcost value.
 9. The method of claim 1, wherein the receiving, by themobile client system, from the first user the unstructured text querycomprises receiving one or more characters of a character string as theuser enters the character string into a graphical user interface. 10.The method of claim 9, further comprising updating, by the mobile clientsystem, one or more of the structured queries by matching a unstructuredtext query that is modified as the user enters one or more subsequentcharacters into the graphical user interface.
 11. The method of claim 1,wherein each node of the set of nodes has a coefficient above athreshold value.
 12. The method of claim 1, further comprisingreceiving, by the mobile computing device, an updated set of grammartemplates or an updated set of nodes from the online social network at apre-determined interval.
 13. The method of claim 1, further comprising,in response to a selection of one of the displayed structured queriesfrom the first user, sending, by the mobile client system, the selectedstructured query to the online social network.
 14. The method of claim13, further comprising receiving, by the mobile client system, one ormore search results in response to the selected structured query beingsent to the online social network.
 15. The method of claim 14, whereineach of the search results corresponds to a particular second node ofthe plurality of second nodes.
 16. The method of claim 1, wherein: theset of nodes comprises a pre-determined number of nodes; and the set ofgrammar templates comprises a pre-determined number of grammartemplates.
 17. One or more computer-readable non-transitory storagemedia embodying software that is operable when executed to: receive, atthe mobile client system, an unstructured text query from a first userof an online social network; parse, by the mobile client system, theunstructured text query into one or more n-grams; access, from a datastore of the mobile client system, a set of nodes of a social graph ofthe online social network, the social graph comprising a plurality ofnodes and a plurality of edges connecting the nodes, the nodescomprising: a first node corresponding to the first user; and aplurality of second nodes that each correspond to a concept or a seconduser associated with the online social network; access, from the datastore of the mobile client system, a set of grammar templates, eachgrammar template comprising one or more non-terminal tokens and one ormore query tokens, wherein the query tokens comprise references to zeroor more second nodes and one or more edges, and wherein each grammartemplate is based on a natural-language string; generate, by the mobileclient system, one or more structured queries by matching theunstructured text query to one or more of the accessed nodes and one ormore of the grammar templates having non-terminal tokens correspondingto the matched nodes, each structured query comprising references to oneor more of the accessed nodes matched to the one or more non-terminaltokens and the zero or more of the second nodes and the one or moreedges referenced in the corresponding grammar template; calculate, bythe mobile client system, a cost for each grammar template based atleast in part on one or more of the n-grams not corresponding to one ofthe non-terminal tokens or query tokens; and display, at the mobileclient system, one or more structured queries to the first user; whereineach non-terminal token and query token has an associated insertioncost; and wherein calculating the cost comprises incurring an insertioncost for each of the non-terminal tokens or query tokens notcorresponding to one or more n-grams.
 18. A system comprising: one ormore processors; and a memory coupled to the processors comprisinginstructions executable by the processors, the processors operable whenexecuting the instructions to: receive, at the mobile client system, anunstructured text query from a first user of an online social network;parse, by the mobile client system, the unstructured text query into oneor more n-grams; access, from a data store of the mobile client system,a set of nodes of a social graph of the online social network, thesocial graph comprising a plurality of nodes and a plurality of edgesconnecting the nodes, the nodes comprising: a first node correspondingto the first user; and a plurality of second nodes that each correspondto a concept or a second user associated with the online social network;access, from the data store of the mobile client system, a set ofgrammar templates, each grammar template comprising one or morenon-terminal tokens and one or more query tokens, wherein the querytokens comprise references to zero or more second nodes and one or moreedges, and wherein each grammar template is based on a natural-languagestring; generate, by the mobile client system, one or more structuredqueries by matching the unstructured text query to one or more of theaccessed nodes and one or more of the grammar templates havingnon-terminal tokens corresponding to the matched nodes, each structuredquery comprising references to one or more of the accessed nodes matchedto the one or more non-terminal tokens and the zero or more of thesecond nodes and the one or more edges referenced in the correspondinggrammar template; calculate, by the mobile client system, a cost foreach grammar template based at least in part on one or more of then-grams not corresponding to one of the non-terminal tokens or querytokens; and display, at the mobile client system, one or more structuredqueries to the first user; wherein each non-terminal token and querytoken has an associated insertion cost; and wherein calculating the costcomprises incurring an insertion cost for each of the non-terminaltokens or query tokens not corresponding to one or more n-grams.